Components.utils.import("chrome://redirector/content/js/redirectorprefs.js"); Components.utils.import("chrome://redirector/content/js/redirector.js"); var RedirectorOverlay = { strings : null, prefs : null, onLoad : function(event) { try { // initialization code document.getElementById('contentAreaContextMenu') .addEventListener("popupshowing", function(e) { RedirectorOverlay.showContextMenu(e); }, false); this.strings = document.getElementById("redirector-strings"); this.prefs = new RedirectorPrefs(); this.changedPrefs(this.prefs); this.prefs.addListener(this); document.addEventListener('keypress', function(event) { if ((event.charCode == 114) && event.altKey) { //alt+r RedirectorOverlay.toggleEnabled(); } }, true); } catch(e) { if (this.strings) { alert(this.strings.getString("initError") + "\n\n" + e); } else { alert(e); } } }, onUnload : function(event) { this.prefs.dispose(); Redirector.debug("Finished cleanup"); }, changedPrefs : function(prefs) { var button = document.getElementById('redirector-button'); document.getElementById('redirector-context').hidden = !prefs.showContextMenu; this.refreshUI(); }, refreshUI: function() { let button = document.getElementById("redirector-button"); let item = document.getElementById("redirector-enabled-item"); if (this.prefs.enabled) { button.removeAttribute('disabled'); item.setAttribute('checked', true); } else { button.setAttribute('disabled', 'yes'); item.setAttribute('checked', false); } }, toggleEnabled: function(event) { this.prefs.enabled = !this.prefs.enabled; this.refreshUI(); }, openSettings : function() { gBrowser.selectedTab = gBrowser.addTab("chrome://redirector/content/redirector.html"); }, updateTooltip: function(event) { AddonManager.getAddonByID("url-rewriter@papush", (addon) => { let label = event.target.getElementsByClassName("redirector-tooltip-version")[0]; label.setAttribute("value", "URL Rewriter " + addon.version); }); } }; window.addEventListener("load", function(event) { RedirectorOverlay.onLoad(event); }, false); window.addEventListener("unload", function(event) { RedirectorOverlay.onUnload(event); }, false);