📄 nsforecastfox.js
字号:
/** * See license.txt *//** * See license.txt *//****************************************************************************** * WARNING!!! This file cannot be used from the main overlay (forecastfox.js). * There are variables and functions that conflict with browser * code and could potentially conflict with other extensions. *****************************************************************************/ /****************************************************************************** * Component Constants *****************************************************************************/ const Cc = Components.classes;const Ci = Components.interfaces;const Cr = Components.results; /****************************************************************************** * File Permission Constants *****************************************************************************/ /*jsl:ignore*/const PERMS_FILE = 0644;const PERMS_DIRECTORY = 0755;/*jsl:end*//****************************************************************************** * File Type Constants *****************************************************************************/const TYPE_PROFILE = Ci.ffIDiskService.TYPE_PROFILE;const TYPE_CACHE = Ci.ffIDiskService.TYPE_CACHE;const TYPE_ICONS = Ci.ffIDiskService.TYPE_ICONS;const TYPE_TEMP = Ci.ffIDiskService.TYPE_TEMP;const TYPE_DEFAULTS = Ci.ffIDiskService.TYPE_DEFAULTS;const TYPE_WEATHERFOX = Ci.ffIDiskService.TYPE_WEATHERFOX;const TYPE_ERRORS = Ci.ffIDiskService.TYPE_ERRORS;/****************************************************************************** * Severity Constants *****************************************************************************/const SEVERITY_INFO = Ci.ffIErrorItem.SEVERITY_INFO;const SEVERITY_WARNING = Ci.ffIErrorItem.SEVERITY_WARNING;const SEVERITY_ERROR = Ci.ffIErrorItem.SEVERITY_ERROR;/****************************************************************************** * Application Constants *****************************************************************************/const FIREFOX_GUID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";const FLOCK_GUID = "{a463f10c-3994-11da-9945-000d60ca027b}";const SUITE_GUID = "{86c18b42-e466-45a9-ae7a-9b95ba6f5640}";const SEAMONKEY_GUID = "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}";const NETSCAPE_GUID = "{3db10fab-e461-4c80-8b97-957ad5f8ea47}"; /****************************************************************************** * Preferences Excluded from Profiles Constant *****************************************************************************/const EXCLUDED_PREFS = { "migrated": true, "migrated.prefs": true, "pinged": true, "icons.version": true, "icons.uninstallfiles": true, "profile.current": true, "profile.switch.delay": true, "profile.switch.enabled": true, "links.alert": true, "links.dialog": true, "links.panel": true, "links.context": true}; /****************************************************************************** * DTD and Namespace Constants for Import, Export, and Profiles.xml *****************************************************************************/const PROFILES_DTD = "http://forecastfox.ensolis.com/specs/1.0/profiles.dtd";const PROFILES_NS = "http://forecastfox.ensolis.com/specs/1.0/profiles";/****************************************************************************** * Gets a preference branch. * * @param Boolean if getting the default branch or current branch. * @param Name of the branch to get. If null is passed then "forecastfox." * is the branch retrieved. * @return Requested preference branch. *****************************************************************************/function getBranch(aDefault, aName){ //forecastf pref branch const FF_NAME = "forecastfox."; //get pref service var pbSvc = Cc["@mozilla.org/preferences-service;1"]. getService(Ci.nsIPrefService); //get the default branch if (aDefault) return (aName) ? pbSvc.getDefaultBranch(aName) : pbSvc.getDefaultBranch(FF_NAME); //get the specified branch return (aName) ? pbSvc.getBranch(aName) : pbSvc.getBranch(FF_NAME);}/****************************************************************************** * Gets a preference. * * @param Name of the preference to retrieve. * @return Requested preference value. *****************************************************************************/var gHelpersBranch = null;function getPref(aName){ //get pref branch if (!gHelpersBranch) gHelpersBranch = getBranch(false, null); var branch = gHelpersBranch; //return value based on pref type var rv = ""; switch (branch.getPrefType(aName)) { case Ci.nsIPrefBranch.PREF_INT: rv = branch.getIntPref(aName); break; case Ci.nsIPrefBranch.PREF_BOOL: rv = branch.getBoolPref(aName); break; case Ci.nsIPrefBranch.PREF_STRING: default: try { rv = branch.getComplexValue(aName, Ci.nsIPrefLocalizedString).data; } catch(e) { try { rv = branch.getComplexValue(aName, Ci.nsISupportsString).data; } catch(e) { rv = branch.getCharPref(aName); } } break; } return rv; }/****************************************************************************** * Sets a preference. * * @param Name of the preference to retrieve. * @param Value to set the preference to. *****************************************************************************/function setPref(aName, aValue){ //get pref branch if (!gHelpersBranch) gHelpersBranch = getBranch(false, null); var branch = gHelpersBranch; //do nothing if value is unchanged var oldValue = getPref(aName); if (aValue == oldValue) return; //remove user value if same as the default var restored = restorePref(aName, aValue); if (restored) return; //set value based on pref type switch (branch.getPrefType(aName)) { case Ci.nsIPrefBranch.PREF_INT: branch.setIntPref(aName, aValue); break; case Ci.nsIPrefBranch.PREF_BOOL: branch.setBoolPref(aName, aValue); break; case Ci.nsIPrefBranch.PREF_STRING: default: try { var plString = Cc["@mozilla.org/pref-localizedstring;1"]. createInstance(Ci.nsIPrefLocalizedString); plString.data = aValue; branch.setComplexValue(aName, Ci.nsIPrefLocalizedString, plString); } catch(e) { try { var sString = Cc["@mozilla.org/supports-string;1"]. createInstance(Ci.nsISupportsString); sString.data = aValue; branch.setComplexValue(aName, Ci.nsISupportsString, sString); } catch(e) { branch.setCharPref(aName, aValue); } } break; } }/****************************************************************************** * Restores a default preference. * * @param Name of the preference to retrieve. * @param The new value of the preference. * @return True if pref was restored *****************************************************************************/function restorePref(aName, aValue){ //get pref branch var branch = getBranch(true, null); //get value based on pref type try { var defaultValue = ""; switch (branch.getPrefType(aName)) { case Ci.nsIPrefBranch.PREF_INT: defaultValue = branch.getIntPref(aName); break; case Ci.nsIPrefBranch.PREF_BOOL: defaultValue = branch.getBoolPref(aName); break; case Ci.nsIPrefBranch.PREF_STRING: default: try { defaultValue = branch.getComplexValue(aName, Ci.nsIPrefLocalizedString).data; } catch(e) { try { defaultValue = branch.getComplexValue(aName, Ci.nsISupportsString).data; } catch(e) { defaultValue = branch.getCharPref(aName); } } break; } } catch(e) { return false; } //value is the same do not restore if (aValue != defaultValue) return false; //get pref branch if (!gHelpersBranch) gHelpersBranch = getBranch(false, null); branch = gHelpersBranch; //clear the value try { branch.clearUserPref(aName); } catch(e) { return false; } // preference was cleared return true;}/****************************************************************************** * Gets the GUID of the applications * * @return A string representing the application ID. *****************************************************************************/var gHelpersGUID = null;function getGUID(){ //return cached GUID if (gHelpersGUID != null) return gHelpersGUID; //use the app info component - toolkit 1.5 or greater if ("nsIXULAppInfo" in Ci) { var app = Cc["@mozilla.org/xre/app-info;1"]. getService(Ci.nsIXULAppInfo); gHelpersGUID = app.ID; } else { //try getting the id from preferences - toolkit 1.0 try { var branch = getBranch(false, ""); gHelpersGUID = branch.getCharPref("app.id"); } catch(e) { //couldn't figure it out so default to the suite - non toolkit gHelpersGUID = SUITE_GUID; } } // get rid of extra characters that are in some people's app.id pref gHelpersGUID = gHelpersGUID.match(/{.*}/)[0]; return gHelpersGUID;}/****************************************************************************** * removes the specified file * * @param File to remove. If file is a directory all files within the * directory will be removed. *****************************************************************************/function removeFile(aFile){ if (aFile.isDirectory()) aFile.remove(true); else aFile.remove(false);}/****************************************************************************** * Gets a directory based on a special directory key. * * @param Special directory key. * @param Array of sub directories from the special directory. * @param Create the sub directory if it doesn't exist. * @return A nsIFile interface for the requested file. *****************************************************************************/function getKeyedDirectory(aKey, aPathArray, aCreate){ //get directory service var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. getService(Ci.nsIProperties); //get base directory var dir = dirSvc.get(aKey, Ci.nsIFile); //loop through path array for (var i=0; i<aPathArray.length; i++) { dir.append(aPathArray[i]); //create directory if instructed if (aCreate && !dir.exists()) dir.create(Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); } return dir;}/****************************************************************************** * Gets a directory from the installed directory. * * @param Array of sub directories from the install directory. * @return A nsIFile interface for the requested file. *****************************************************************************/function getInstallDirectory(aPathArray){ //setup objects var dir = null; //get extension manager - toolkit 1.0 or greater if ("@mozilla.org/extensions/manager;1" in Cc) { var em = Cc["@mozilla.org/extensions/manager;1"]. getService(Ci.nsIExtensionManager); //get install location from extension manager - toolkit 1.5 if ("nsIInstallLocation" in Ci) { dir = em.getInstallLocation("{0538E3E3-7E9B-4d49-8831-A227C80A7AD3}"); dir = dir.getItemLocation("{0538E3E3-7E9B-4d49-8831-A227C80A7AD3}"); } } //couldn't use extension manager so try the profile directory - non toolkit if (!dir) { var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. getService(Ci.nsIProperties); dir = dirSvc.get("ProfD", Ci.nsIFile); dir.append("extensions"); dir.append("{0538E3E3-7E9B-4d49-8831-A227C80A7AD3}"); //not in the profile directory so it must be in the app directory if (!dir.exists()) { dir = dirSvc.get("XCurProcD", Ci.nsIFile); dir.append("extensions"); dir.append("{0538E3E3-7E9B-4d49-8831-A227C80A7AD3}"); } } //loop through path array for (var i=0; i<aPathArray.length; i++) dir.append(aPathArray[i]); return dir;} /****************************************************************************** * Get the top most open window. A window has to open for this to be called. * Use this if the type of window does not matter. * * @return A window object used for modality. *****************************************************************************/function getTopWindow(){ //get top window var mediator = Cc["@mozilla.org/appshell/window-mediator;1"]. getService(Ci.nsIWindowMediator); return mediator.getMostRecentWindow(null); } /****************************************************************************** * Get the main application window. Use this if the type of window does matter.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -