Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add web developer menu item to enable/disable for current tab

  • Loading branch information...
commit cefdc0b1a30486abba85d05f421e94944493628c 1 parent d4b5c7c
benmmurphy authored
Showing with 116 additions and 83 deletions.
  1. +12 −2 chrome/content/firefoxOverlay.xul
  2. +104 −81 chrome/content/overlay.js
14 chrome/content/firefoxOverlay.xul
View
@@ -2,6 +2,16 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://jsbeautifier/content/overlay.js"/>
<statusbar id="status-bar">
- <statusbarpanel id="jsbStatus" label="JSB"/>
+ <statusbarpanel id="jsbStatus" label="JSB"/>
</statusbar>
-</overlay>
+ <menupopup id="menuWebDeveloperPopup">
+ <menu insertbefore="webConsole" id="appmenu_jsdeminifier" label="JS Deminifier">
+ <menupopup>
+ <menuitem type="checkbox" checked="false" id="enable_jsdeminifier" label="Enable for Current Tab"/>
+ <menuitem type="checkbox" checked="true" id="disable_jsdeminifier" label="Disable for Current Tab"/>
+ </menupopup>
+ </menu>
+ <menuseperator insertbefore="webConsole"/>
+ </menupopup>
+
+</overlay>
185 chrome/content/overlay.js
View
@@ -1,91 +1,114 @@
(function() {
- Components.utils.import("resource://jsbeautifier_js/module.js");
+ Components.utils.import("resource://jsbeautifier_js/module.js");
- function selected_config() {
-
- if (gBrowser.selectedBrowser == null) {
- return null;
- }
- var browser = gBrowser.selectedBrowser;
- if (browser != null) {
+ function selected_config() {
+
+ if (gBrowser.selectedBrowser == null) {
+ return null;
+ }
+ var browser = gBrowser.selectedBrowser;
+ if (browser != null) {
- var cfg = jsbeautifier.getConfig(browser);
- return cfg;
- }
-
- return null;
- };
-
- function update_text() {
-
-
-
- var label = "JSB OFF";
+ var cfg = jsbeautifier.getConfig(browser);
+ return cfg;
+ }
+
+ return null;
+ };
- var cfg = selected_config();
- if (cfg != null) {
- label = cfg.active ? "JSB ON" : "JSB OFF";
- }
-
-
- document.getElementById("jsbStatus").label = label;
- };
+ function update_text() {
+ var enabled = get_enabled();
+ update_status_text(enabled);
+ update_menu(enabled);
+ }
- function toggle() {
-
- var cfg = selected_config();
- if (cfg != null) {
- cfg.active = !cfg.active;
- update_text();
- }
-
- };
+ function get_enabled() {
+ var cfg = selected_config();
+ return cfg == null ? false : cfg.active;
+ }
- function load() {
- hookup_tabs();
- document.getElementById("jsbStatus").addEventListener("click", toggle, false);
- update_text();
- };
-
- function unload() {
- var container = gBrowser.tabContainer;
- for (var i = 0; i < container.childNodes.length; ++i) {
- jsbeautifier.remove(gBrowser.getBrowserForTab(container.childNodes[i]));
- }
- container.removeEventListener("TabOpen", tabOpen, false);
- container.removeEventListener("TabClose", tabClose, false);
- container.removeEventListener("TabSelect", tabClose, false);
- };
-
- function tabOpen(event) {
- var browser = gBrowser.getBrowserForTab(event.target);
- jsbeautifier.add(browser, window.Worker);
- };
-
- function tabClose(event) {
- var browser = gBrowser.getBrowserForTab(event.target);
- jsbeautifier.remove(browser);
- };
-
- function tabSelect(event) {
- update_text();
- };
-
+ function update_menu(enabled) {
+ document.getElementById("enable_jsdeminifier").setAttribute("checked", enabled ? "true" : "false");
+ document.getElementById("disable_jsdeminifier").setAttribute("checked", enabled ? "false" : "true");
+ }
- function hookup_tabs() {
- var container = gBrowser.tabContainer;
- if (container) {
- container.addEventListener("TabOpen", tabOpen, false);
- container.addEventListener("TabClose", tabClose, false);
- container.addEventListener("TabSelect", tabSelect, false);
- for (var i = 0; i < container.childNodes.length; ++i) {
- jsbeautifier.add(gBrowser.getBrowserForTab(container.childNodes[i]), window.Worker);
- }
- }
- }
-
- window.addEventListener("load", load, false);
- window.addEventListener("unload", unload, false);
+ function update_status_text(enabled) {
+ document.getElementById("jsbStatus").label = enabled ? "JSB ON" : "JSB OFF";
+ }
+
+ function toggle() {
+
+ var cfg = selected_config();
+ if (cfg != null) {
+ cfg.active = !cfg.active;
+ update_text();
+ }
+
+ };
+
+ function set_active(active) {
+ var cfg = selected_config();
+ if (cfg != null) {
+ cfg.active = active;
+ update_text();
+ }
+ }
+
+ function disable() {
+ set_active(false);
+ }
+
+ function enable() {
+ set_active(true);
+ }
+
+ function load() {
+ hookup_tabs();
+ document.getElementById("jsbStatus").addEventListener("click", toggle, false);
+ document.getElementById("enable_jsdeminifier").addEventListener("command", enable, false);
+ document.getElementById("disable_jsdeminifier").addEventListener("command", disable, false);
+ update_text();
+ };
+
+ function unload() {
+ var container = gBrowser.tabContainer;
+ for (var i = 0; i < container.childNodes.length; ++i) {
+ jsbeautifier.remove(gBrowser.getBrowserForTab(container.childNodes[i]));
+ }
+ container.removeEventListener("TabOpen", tabOpen, false);
+ container.removeEventListener("TabClose", tabClose, false);
+ container.removeEventListener("TabSelect", tabClose, false);
+ };
+
+ function tabOpen(event) {
+ var browser = gBrowser.getBrowserForTab(event.target);
+ jsbeautifier.add(browser, window.Worker);
+ };
+
+ function tabClose(event) {
+ var browser = gBrowser.getBrowserForTab(event.target);
+ jsbeautifier.remove(browser);
+ };
+
+ function tabSelect(event) {
+ update_text();
+ };
+
+
+ function hookup_tabs() {
+ var container = gBrowser.tabContainer;
+ if (container) {
+ container.addEventListener("TabOpen", tabOpen, false);
+ container.addEventListener("TabClose", tabClose, false);
+ container.addEventListener("TabSelect", tabSelect, false);
+ for (var i = 0; i < container.childNodes.length; ++i) {
+ jsbeautifier.add(gBrowser.getBrowserForTab(container.childNodes[i]), window.Worker);
+ }
+ }
+ }
+
+ window.addEventListener("load", load, false);
+ window.addEventListener("unload", unload, false);
})();
Please sign in to comment.
Something went wrong with that request. Please try again.