132
edits
No edit summary |
(Added bookmarks examples, fixed up the browser examples, removed the database examples.) |
||
Line 4: | Line 4: | ||
=== Browser === | === Browser === | ||
* Access browser tabs | * Access browser tabs | ||
* Access web content in a tab | * Access web content in a tab | ||
* Handle tab-related events | |||
'''Example:''' | '''Example:''' | ||
Open, and activate, a new tab | Open, and activate, a new tab | ||
Application.browser.open("http://google.com/").active = true; | |||
Open, and activate, a tab just after the current tab | Open, and activate, a tab just after the current tab | ||
var tab = | var tab = Application.browser.open("http://google.com/"); | ||
Application.browser.insertBefore( tab, Application.browser.activeTab.next ); | |||
tab.active = true; | tab.active = true; | ||
or: | or: | ||
var tab = | var tab = Application.browser.open("http://google.com/"); | ||
tab.index = | tab.index = Application.browser.activeTab + 1; | ||
tab.active = true; | tab.active = true; | ||
Move the active tab to be the first tab | Move the active tab to be the first tab | ||
Application.browser.insertBefore( | |||
Application.browser.activeTab, | |||
Application.browser.tabs[0] | |||
); | |||
or: | or: | ||
Application.browser.activeTab.index = 0; | |||
Close the active tab | Close the active tab | ||
Application.browser.activeTab.close(); | |||
Do something when the active tab loads | Do something when the active tab loads | ||
Application.browser.activeTab.events.addListener( "load", function(){ | |||
this.query("#foo div") | this.query("#foo div") | ||
}); | }); | ||
Change the URL in the active tab | Change the URL in the active tab | ||
Application.browser.activeTab.url = "http://mozilla.org/"; | |||
Close all Google-related tabs | Close all Google-related tabs | ||
Application.browser.tabs.forEach(function(tab){ | |||
if ( tab.url.match(/google/) ) | if ( tab.url.match(/google/) ) | ||
tab.remove(); | tab.remove(); | ||
Line 50: | Line 51: | ||
Re-use a tab, or open a new one | Re-use a tab, or open a new one | ||
var url = "http://google.com/"; | var url = "http://google.com/"; | ||
Application.browser.tabs.some(function(tab){ | |||
if ( tab.url == url ) | if ( tab.url == url ) | ||
return tab.active = true; | return tab.active = true; | ||
}) || | }) || Application.browser.open( url ).active = true; | ||
Stop the user from opening any new tabs | Stop the user from opening any new tabs | ||
Application.browser.events.addListener( "TabOpen", function(e){ | |||
e.target.close(); | e.target.close(); | ||
}); | }); | ||
Line 66: | Line 67: | ||
'''Example:''' | '''Example:''' | ||
Log the title of all top-level bookmarks: | |||
Application.bookmarks.all.forEach(function(cur){ | |||
console.log( "title", cur.title ); | 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(); | |||
}); | |||
var | 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 ); | |||
edits