FUEL/0.2/Plan

From MozillaWiki
< FUEL‎ | 0.2
Jump to: navigation, search

< FUEL/0.2
Due Date: May 25, 2007
Deliverable: Complete API

Browser

  • Access browser tabs
  • Access web content in a tab
  • Handle tab-related events

Example:

Open, and activate, a new tab

 Application.browser.open("http://google.com/").active = true;

Open, and activate, a tab just after the current tab

 var tab = Application.browser.open("http://google.com/");
 Application.browser.insertBefore( tab, Application.browser.activeTab.next );
 tab.active = true;

or:

 var tab = Application.browser.open("http://google.com/");
 tab.index = Application.browser.activeTab + 1;
 tab.active = true;

Move the active tab to be the first tab

 Application.browser.insertBefore(
   Application.browser.activeTab,
   Application.browser.tabs[0]
 );

or:

 Application.browser.activeTab.index = 0;

Close the active tab

 Application.browser.activeTab.close();

Do something when the active tab loads

 Application.browser.activeTab.events.addListener( "load", function(){
   this.query("#foo div")
 });

Change the URL in the active tab

 Application.browser.activeTab.url = "http://mozilla.org/";

Close all Google-related tabs

 Application.browser.tabs.forEach(function(tab){
   if ( tab.url.match(/google/) )
     tab.remove();
 });

Re-use a tab, or open a new one

 var url = "http://google.com/";
 Application.browser.tabs.some(function(tab){
   if ( tab.url == url )
     return tab.active = true;
 }) || Application.browser.open( url ).active = true;

Stop the user from opening any new tabs

 Application.browser.events.addListener( "TabOpen", function(e){
   e.target.close();
 });

Bookmarks

  • Add A Bookmark
  • Browse Bookmarks

Example:

Log the title of all top-level bookmarks:

 Application.bookmarks.all.forEach(function(cur){
 	console.log( "title", cur.title );
 });

Add a new bookmark:

 Application.bookmarks.add("Mozilla", "http://mozilla.org/");

Remove all bookmarks that point to Google:

 Application.bookmarks.all.forEach(function(cur){
   if ( cur.url.match(/google.com/) )
     cur.remove();
 });

Add a new bookmark, if one doesn't already exist:

 var url = "http://google.com/";
 Application.bookmarks.all.some(function(cur){
   if ( cur.url == url )
     return true;
 }) || Application.bookmarks.add( "Google", url );