MozillaZine

Jetpack: How to open new tab with URL on icon click?

Talk about add-ons and extension development.
abcuser
 
Posts: 88
Joined: March 12th, 2007, 11:19 pm
May 30th, 2009, 7:13 am

Post Posted May 30th, 2009, 7:13 am

Hi,
I have installed JetPack, new Firefox extension system for making html, css and javascrip extensions.

The problem
Every day in the morning in my job I have to check 5 URL addresses to see if there are any errors on servers. Now I do this by executing one bookmark after another. It would be nice if for example clicking on icon on status bar would open all URL addresses in new tabs.

What I would like to do
I would like to write extension in JetPack and do the following:
1. add new icon in status bar
2. when I click on this icon 5 new tabs should be opened with 5 URL addresses I would specify in code.

I am bad programmer - I used to write some simple programs 10 years ago. I just read tutorial
https://jetpack.mozillalabs.com/tutorial.html and I see the last sample "Chapter 5: Email Notifier" does something to open gmail.com web page in new tab. But I am unable to figured out which code is needed to solve my problem.

I also installed "Email Notifier - Status Bar Demo" from https://jetpack.mozillalabs.com/ to confirm, that clicking on icon from status bar really opens up new tab.

So above Email Notifier extension has the solution, but I am just unable to figure out which lines of code is needed.

Any idea how to write such a simple JetPack extension?
Regards

ake79
 
Posts: 733
Joined: February 17th, 2007, 6:05 am
May 30th, 2009, 12:59 pm

Post Posted May 30th, 2009, 12:59 pm

I don't know anything about jetpack, but what about built-in functionality?

http://lifehacker.com/246643/how-to-wor ... in-firefox
Save File to - Save files to user-defined folders and their sub-folders straight from context menu
ThumbsDown - Bulk image downloader

abcuser
 
Posts: 88
Joined: March 12th, 2007, 11:19 pm
May 31st, 2009, 10:33 am

Post Posted May 31st, 2009, 10:33 am

ake79, beside solving this problem I would also like to learn JetPack, so JetPack solution would be great.

Zoolcar9

User avatar
 
Posts: 1571
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia
May 31st, 2009, 6:03 pm

Post Posted May 31st, 2009, 6:03 pm

 
Example script
Code: Select all
function Google() {}

Google.prototype = {
  url: "http://www.google.com/",

  // open a url in a new tab
  open: function() {
    jetpack.tabs.open(this.url);
  }
};

// add to statusbar
jetpack.statusBar.append({
  html: <>
    <div><img id="icon" /></div>
  </>,

  width: 16,

  onReady: function (doc) {
    var google = new Google(doc);

    // add icon
    $("img#icon", doc).attr("src", google.url + "favicon.ico");

    // add click event
    $(doc).click(function(e) {
      if (e.button == 0) google.open();
    })
  }
})

Go figure.
 

abcuser
 
Posts: 88
Joined: March 12th, 2007, 11:19 pm
June 1st, 2009, 5:30 am

Post Posted June 1st, 2009, 5:30 am

Zoolcar9,
thanks a lot. I have modified your code to meet my needs.

If someone is interested in this JetPack extension do the following:

1. Save bellow code to ExecuteWebPage.js file on local disk.
Code: Select all
function MyWebPage() {}

MyWebPage.prototype = {
  url: "http://www.google.com/",

  // open urls in a new tabs
  open: function() {
    jetpack.tabs.open("http://www.google.com/");
    jetpack.tabs.open("http://www.yahoo.com/");
    jetpack.tabs.open("http://www.ask.com/");
  }
};

// add to statusbar
jetpack.statusBar.append({
  html: <>
    <div><img id="icon" /></div>
  </>,

  width: 16,

  onReady: function (doc) {
    var mywebpage = new MyWebPage(doc);

    // add icon
    $("img#icon", doc).attr("src", mywebpage.url + "favicon.ico");

    // add click event
    $(doc).click(function(e) {
      if (e.button == 0) mywebpage.open();
    })
  }
})

2. Save the following code to ExecuteWebPage.html file on local disk.
Code: Select all
<html>
<head>
<link rel="jetpack" href="ExecuteWebPage.js" name="ExecuteWebPage"/>
</head>
<body>
</body>
</html>

3. File | Open File and open ExecuteWebPage.html file. Firefox will give up Install bar and after Install click on button security warning appears, just accept this warning and continue.
4. In right bottom there is new icon (Google icon). Click on it to open Google.com, Yahoo.com and Ask.com in new tab each. Just change the code if you would like to open any other URL address.

By the way, is there any place to officially publish this new JetPack extension?
Regards

Zoolcar9

User avatar
 
Posts: 1571
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia
June 2nd, 2009, 5:52 pm

Post Posted June 2nd, 2009, 5:52 pm

abcuser wrote:By the way, is there any place to officially publish this new JetPack extension?

http://userscripts.org/jetpacks
 

abcuser
 
Posts: 88
Joined: March 12th, 2007, 11:19 pm
June 2nd, 2009, 10:27 pm

Post Posted June 2nd, 2009, 10:27 pm

Zoolcar9, I have published this extension on web page you specified. Thanks a lot for help.

Return to Extension Development


Who is online

Users browsing this forum: MSN [Bot] and 3 guests