OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of the Adblock Plus, |
| 3 * Copyright (C) 2006-2012 Eyeo GmbH |
| 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 /** |
| 19 * @fileOverview Adds typo correction feature |
| 20 */ |
| 21 |
| 22 Cu.import("resource://gre/modules/AddonManager.jsm"); |
| 23 |
| 24 let {Prefs} = require("prefs"); |
| 25 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}"; |
| 26 let addonListener = null; |
| 27 |
| 28 function init() |
| 29 { |
| 30 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos
)) |
| 31 { |
| 32 AddonManager.getAddonByID(urlfixerID, function(addon) |
| 33 { |
| 34 startTypoCorrection(addon && addon.isActive); |
| 35 }); |
| 36 } |
| 37 else |
| 38 { |
| 39 let onPrefChange = function(name) |
| 40 { |
| 41 if (name == "correctTypos" && Prefs[name]) |
| 42 { |
| 43 init(); |
| 44 Prefs.removeListener(onPrefChange); |
| 45 } |
| 46 } |
| 47 |
| 48 Prefs.addListener(onPrefChange); |
| 49 } |
| 50 } |
| 51 |
| 52 function startTypoCorrection(isInstalledAndEnabled) |
| 53 { |
| 54 if (isInstalledAndEnabled) |
| 55 require("typoFixer").detachWindowObserver(); |
| 56 else |
| 57 require("typoFixer").attachWindowObserver(); |
| 58 |
| 59 if (!addonListener) |
| 60 { |
| 61 addonListener = { |
| 62 onEnabling: function(addon, needsRestart) |
| 63 { |
| 64 if (addon.id == urlfixerID) |
| 65 startTypoCorrection(true); |
| 66 }, |
| 67 onDisabled: function(addon) |
| 68 { |
| 69 if (addon.id == urlfixerID) |
| 70 startTypoCorrection(false); |
| 71 }, |
| 72 onInstalling: function(addon, needsRestart) |
| 73 { |
| 74 if (addon.id == urlfixerID) |
| 75 startTypoCorrection(true); |
| 76 }, |
| 77 onUninstalled: function(addon) |
| 78 { |
| 79 if (addon.id == urlfixerID) |
| 80 startTypoCorrection(false); |
| 81 } |
| 82 } |
| 83 |
| 84 AddonManager.addAddonListener(addonListener); |
| 85 onShutdown.add(function() AddonManager.removeAddonListener(addonListener)); |
| 86 } |
| 87 } |
| 88 |
| 89 init(); |
OLD | NEW |