📄 nsforecastfox.js
字号:
* * @return A window object used for modality. *****************************************************************************/function getMainWindow(){ /** this may need to change if main window of a supported app is not "navigator:browser" **/ //get the mediator service var mediator = Cc["@mozilla.org/appshell/window-mediator;1"]. getService(Ci.nsIWindowMediator); //get the app window var main = mediator.getMostRecentWindow("navigator:browser"); if (main) return main; //get the watcher service var watcher = Cc["@mozilla.org/embedcomp/window-watcher;1"]. getService(Ci.nsIWindowWatcher); //open a new window switch (getGUID()) { case SUITE_GUID: case SEAMONKEY_GUID: main = watcher.openWindow(null, "chrome://navigator/content/navigator.xul", "_blank", "chrome,all,dialog=no", "about:blank"); break; case FIREFOX_GUID: case NETSCAPE_GUID: case FLOCK_GUID: default: main = watcher.openWindow(null, "chrome://browser/content/browser.xul", "_blank", "chrome,all,dialog=no", "about:blank"); break; } return main;} /****************************************************************************** * String enumerator of hash table keys. * * @param Javascript hash table. * @return A nsIStringEnumerator of the keys. *****************************************************************************/function KeyEnumerator(aHashTable){ //setup key array this._keys = []; this._index = 0; //load with data if (aHashTable) { for (var name in aHashTable) this._keys.push(name); }}KeyEnumerator.prototype = { _index: null, _keys: null, QueryInterface: function KeyEnumerator_QueryInterface(aIID) { if (!aIID.equals(Ci.nsIStringEnumerator) || !aIID.equals(Ci.nsISupports)) throw Cr.NS_ERROR_NO_INTERFACE; return this; }, hasMore: function KeyEnumerator_hasMore() { return this._index < this._keys.length; }, getNext: function KeyEnumerator_getNext() { var rv = this._keys[this._index]; this._index++; return rv; }};/****************************************************************************** * Sorts an array ascending where the items have a name property. * * @param Current array item. * @param Next array item. * * @return 1 if greater, 0 if equal, and -1 if less than. *****************************************************************************/function sortByName(aItem1, aItem2){ if (aItem1.name < aItem2.name) return -1; else if (aItem1.name == aItem2.name) return 0; return 1;}/****************************************************************************** * Get a new prompter. * * @param The parent window for the prompter can be null. * * @return A new prompter. *****************************************************************************/function getPrompter(aParent){ //get the watcher service var watcher = Cc["@mozilla.org/embedcomp/window-watcher;1"]. getService(Ci.nsIWindowWatcher); //return a prompter return watcher.getNewPrompter(aParent);}/****************************************************************************** * Gets the forecastfox string bundle. * * @return A nsIStringBundle interface for the requested url. *****************************************************************************/var gHelpersBundle = null;function getBundle(){ if (gHelpersBundle != null) return gHelpersBundle; const BUNDLE_URL = "chrome://forecastfox/locale/forecastfox.properties"; //get the stringbundle service var sbSvc = Cc["@mozilla.org/intl/stringbundle;1"]. getService(Ci.nsIStringBundleService); //get the bundle and return it gHelpersBundle = sbSvc.createBundle(BUNDLE_URL); return gHelpersBundle;}/****************************************************************************** * Checks if the alert service is included. * * @return True if alert service is present. *****************************************************************************/var gHelpersHasAlert = null;function checkAlertService(){ //return cached alert check if (gHelpersHasAlert != null) return gHelpersHasAlert; //check if the alert interface exists if ("nsIAlertsService" in Ci) gHelpersHasAlert = true; else gHelpersHasAlert = false; //cache the flag and return the value return gHelpersHasAlert;}/****************************************************************************** * Checks if the application can handle our overflow code. * * @return True if the app can. *****************************************************************************/ var gHelpersCanOverflow = null;function canOverflow() { //return cached check if (gHelpersCanOverflow != null) return gHelpersCanOverflow; gHelpersCanOverflow = false; switch(getGUID()) { //app can overflow case FIREFOX_GUID: case SEAMONKEY_GUID: gHelpersCanOverflow = true; break; //app cannot overflow case SUITE_GUID: case FLOCK_GUID: case NETSCAPE_GUID: default: gHelpersCanOverflow = false; break; } //return the value return gHelpersCanOverflow;}/****************************************************************************** * Open a link in the main application window * * @param The url to open. * @param Where to open the link (current, window, tab, tabshifted) *****************************************************************************/ function openLink(aURL, aWhere){ /* XXX may need to change this code if main window of a supported app is not a browser */ var win = getMainWindow(); var browser = win.document.getElementById("content"); var features = "chrome,all,dialog=no"; var chrome = ""; switch (aWhere) { //open in a new window case "window": switch (getGUID()) { //apps with navigator.xul as main window case SEAMONKEY_GUID: case SUITE_GUID: chrome = "chrome://navigator/content/navigator.xul"; win.openDialog(chrome, "_blank", features, aURL, null, null); break; //apps with browser.xul as main window case FIREFOX_GUID: case NETSCAPE_GUID: case FLOCK_GUID: default: chrome = "chrome://browser/content/browser.xul"; win.openDialog(chrome, "_blank", features, aURL, null, null); break; } break; //open in a new tab case "tab": case "tabshifted": var tab = browser.addTab(aURL); //focus the tab if (aWhere == "tab") { browser.selectedTab = tab; win.content.focus(); } break; //open in the current tab case "current": default: browser.loadURI(aURL); win.content.focus(); break; }}/****************************************************************************** * Generic item constructor used by different item components as * a prototype for the component. * * @param Component name. ******************************************************************************/function ItemBase(aName){ this._name = aName; this._ifaces = [this.interfaceID, Ci.ffIItem, Ci.nsIClassInfo, Ci.nsISupports];}ItemBase.prototype = { _name: null, _ifaces: null, //////////////////////////////// // nsISupports QueryInterface: function ItemBase_QueryInterface(aIID) { var ifaces = this.getInterfaces({}); for (var i=0; i<ifaces.length; i++) { if (aIID.equals(ifaces[i])) return this; } throw Cr.NS_ERROR_NO_INTERFACE; }, //////////////////////////////// // nsIClassInfo getInterfaces: function ItemBase_getInterfaces(aCount) { aCount.value = this._ifaces.length; return this._ifaces; }, getHelperForLanguage: function ItemBase_getHelperForLanguage(aLanguage) { return null; }, get contractID() { return gComponents[this._name].contractID; }, get classID() { return gComponents[this._name].classID; }, get classDescription() { return gComponents[this._name].className; }, get implementationLanguage() { return Ci.nsIProgrammingLanguage.JAVASCRIPT; }, get flags() { return Ci.nsIClassInfo.MAIN_THREAD_ONLY; }, //////////////////////////////// // ffIItem /** * Unique ID of the item. */ get ID() { return this.getProperty("ID"); }, /** * String enumerator of property names. * */ get properties() { return new KeyEnumerator(this._properties); }, /** * Check if a given property is present in the item. * * @param Name of the property to check. * @return True if present, false if absent. */ hasProperty: function ItemBase_hasProperty(aName) { return this._properties.hasOwnProperty(aName); }, /** * Retrieves a specific property from the item. * * @param Name of the property to retrieve. * @return The value of the property or null if property doesn't exist */ getProperty: function ItemBase_getProperty(aName) { if (!this.hasProperty(aName)) return null; else return this._properties[aName]; }, /** * Sets a specific property for the item. * * @param Name of the property to set. * @param The value to set. */ setProperty: function ItemBase_setProperty(aName, aValue) { this._properties[aName] = aValue; }, /** * Removes a property. * * @param Name of property to remove. */ deleteProperty: function ItemBase_deleteProperty(aName) { //do nothing if property not set if (!this.hasProperty(aName)) return; //delete the property delete this._properties[aName]; }, /** * Make a duplicate copy of a item. * * @return A item with the same values as the current item. */ clone: function ItemBase_clone() { //create a new item var item = Cc[this.contractID].createInstance(this.interfaceID); //loop through all properties and set on new item for (var name in this._properties) item.setProperty(name, this._properties[name]); //return the new item return item; }, //////////////////////////////// // Internal Functions /** * Helper property to get the main interface. */ get interfaceID() { return gComponents[this._name].interfaceID; } };/****************************************************************************** * Generic service constructor used by different service components as * a prototype for the component. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -