Skip to content
This repository
Browse code

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

  • Loading branch information...
commit cefdc0b1a30486abba85d05f421e94944493628c 1 parent d4b5c7c
benmmurphy authored

Showing 2 changed files with 116 additions and 83 deletions. Show diff stats Hide diff stats

  1. +12 2 chrome/content/firefoxOverlay.xul
  2. +104 81 chrome/content/overlay.js
14 chrome/content/firefoxOverlay.xul
@@ -2,6 +2,16 @@
2 2 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
3 3 <script type="application/x-javascript" src="chrome://jsbeautifier/content/overlay.js"/>
4 4 <statusbar id="status-bar">
5   - <statusbarpanel id="jsbStatus" label="JSB"/>
  5 + <statusbarpanel id="jsbStatus" label="JSB"/>
6 6 </statusbar>
7   -</overlay>
  7 + <menupopup id="menuWebDeveloperPopup">
  8 + <menu insertbefore="webConsole" id="appmenu_jsdeminifier" label="JS Deminifier">
  9 + <menupopup>
  10 + <menuitem type="checkbox" checked="false" id="enable_jsdeminifier" label="Enable for Current Tab"/>
  11 + <menuitem type="checkbox" checked="true" id="disable_jsdeminifier" label="Disable for Current Tab"/>
  12 + </menupopup>
  13 + </menu>
  14 + <menuseperator insertbefore="webConsole"/>
  15 + </menupopup>
  16 +
  17 +</overlay>
185 chrome/content/overlay.js
... ... @@ -1,91 +1,114 @@
1 1 (function() {
2   - Components.utils.import("resource://jsbeautifier_js/module.js");
  2 + Components.utils.import("resource://jsbeautifier_js/module.js");
3 3
4   - function selected_config() {
5   -
6   - if (gBrowser.selectedBrowser == null) {
7   - return null;
8   - }
9   - var browser = gBrowser.selectedBrowser;
10   - if (browser != null) {
  4 + function selected_config() {
  5 +
  6 + if (gBrowser.selectedBrowser == null) {
  7 + return null;
  8 + }
  9 + var browser = gBrowser.selectedBrowser;
  10 + if (browser != null) {
11 11
12   - var cfg = jsbeautifier.getConfig(browser);
13   - return cfg;
14   - }
15   -
16   - return null;
17   - };
18   -
19   - function update_text() {
20   -
21   -
22   -
23   - var label = "JSB OFF";
  12 + var cfg = jsbeautifier.getConfig(browser);
  13 + return cfg;
  14 + }
  15 +
  16 + return null;
  17 + };
24 18
25   - var cfg = selected_config();
26   - if (cfg != null) {
27   - label = cfg.active ? "JSB ON" : "JSB OFF";
28   - }
29   -
30   -
31   - document.getElementById("jsbStatus").label = label;
32   - };
  19 + function update_text() {
  20 + var enabled = get_enabled();
  21 + update_status_text(enabled);
  22 + update_menu(enabled);
  23 + }
33 24
34   - function toggle() {
35   -
36   - var cfg = selected_config();
37   - if (cfg != null) {
38   - cfg.active = !cfg.active;
39   - update_text();
40   - }
41   -
42   - };
  25 + function get_enabled() {
  26 + var cfg = selected_config();
  27 + return cfg == null ? false : cfg.active;
  28 + }
43 29
44   - function load() {
45   - hookup_tabs();
46   - document.getElementById("jsbStatus").addEventListener("click", toggle, false);
47   - update_text();
48   - };
49   -
50   - function unload() {
51   - var container = gBrowser.tabContainer;
52   - for (var i = 0; i < container.childNodes.length; ++i) {
53   - jsbeautifier.remove(gBrowser.getBrowserForTab(container.childNodes[i]));
54   - }
55   - container.removeEventListener("TabOpen", tabOpen, false);
56   - container.removeEventListener("TabClose", tabClose, false);
57   - container.removeEventListener("TabSelect", tabClose, false);
58   - };
59   -
60   - function tabOpen(event) {
61   - var browser = gBrowser.getBrowserForTab(event.target);
62   - jsbeautifier.add(browser, window.Worker);
63   - };
64   -
65   - function tabClose(event) {
66   - var browser = gBrowser.getBrowserForTab(event.target);
67   - jsbeautifier.remove(browser);
68   - };
69   -
70   - function tabSelect(event) {
71   - update_text();
72   - };
73   -
  30 + function update_menu(enabled) {
  31 + document.getElementById("enable_jsdeminifier").setAttribute("checked", enabled ? "true" : "false");
  32 + document.getElementById("disable_jsdeminifier").setAttribute("checked", enabled ? "false" : "true");
  33 + }
74 34
75   - function hookup_tabs() {
76   - var container = gBrowser.tabContainer;
77   - if (container) {
78   - container.addEventListener("TabOpen", tabOpen, false);
79   - container.addEventListener("TabClose", tabClose, false);
80   - container.addEventListener("TabSelect", tabSelect, false);
81   - for (var i = 0; i < container.childNodes.length; ++i) {
82   - jsbeautifier.add(gBrowser.getBrowserForTab(container.childNodes[i]), window.Worker);
83   - }
84   - }
85   - }
86   -
87   - window.addEventListener("load", load, false);
88   - window.addEventListener("unload", unload, false);
  35 + function update_status_text(enabled) {
  36 + document.getElementById("jsbStatus").label = enabled ? "JSB ON" : "JSB OFF";
  37 + }
  38 +
  39 + function toggle() {
  40 +
  41 + var cfg = selected_config();
  42 + if (cfg != null) {
  43 + cfg.active = !cfg.active;
  44 + update_text();
  45 + }
  46 +
  47 + };
  48 +
  49 + function set_active(active) {
  50 + var cfg = selected_config();
  51 + if (cfg != null) {
  52 + cfg.active = active;
  53 + update_text();
  54 + }
  55 + }
  56 +
  57 + function disable() {
  58 + set_active(false);
  59 + }
  60 +
  61 + function enable() {
  62 + set_active(true);
  63 + }
  64 +
  65 + function load() {
  66 + hookup_tabs();
  67 + document.getElementById("jsbStatus").addEventListener("click", toggle, false);
  68 + document.getElementById("enable_jsdeminifier").addEventListener("command", enable, false);
  69 + document.getElementById("disable_jsdeminifier").addEventListener("command", disable, false);
  70 + update_text();
  71 + };
  72 +
  73 + function unload() {
  74 + var container = gBrowser.tabContainer;
  75 + for (var i = 0; i < container.childNodes.length; ++i) {
  76 + jsbeautifier.remove(gBrowser.getBrowserForTab(container.childNodes[i]));
  77 + }
  78 + container.removeEventListener("TabOpen", tabOpen, false);
  79 + container.removeEventListener("TabClose", tabClose, false);
  80 + container.removeEventListener("TabSelect", tabClose, false);
  81 + };
  82 +
  83 + function tabOpen(event) {
  84 + var browser = gBrowser.getBrowserForTab(event.target);
  85 + jsbeautifier.add(browser, window.Worker);
  86 + };
  87 +
  88 + function tabClose(event) {
  89 + var browser = gBrowser.getBrowserForTab(event.target);
  90 + jsbeautifier.remove(browser);
  91 + };
  92 +
  93 + function tabSelect(event) {
  94 + update_text();
  95 + };
  96 +
  97 +
  98 + function hookup_tabs() {
  99 + var container = gBrowser.tabContainer;
  100 + if (container) {
  101 + container.addEventListener("TabOpen", tabOpen, false);
  102 + container.addEventListener("TabClose", tabClose, false);
  103 + container.addEventListener("TabSelect", tabSelect, false);
  104 + for (var i = 0; i < container.childNodes.length; ++i) {
  105 + jsbeautifier.add(gBrowser.getBrowserForTab(container.childNodes[i]), window.Worker);
  106 + }
  107 + }
  108 + }
  109 +
  110 + window.addEventListener("load", load, false);
  111 + window.addEventListener("unload", unload, false);
89 112
90 113
91 114 })();

0 comments on commit cefdc0b

Please sign in to comment.
Something went wrong with that request. Please try again.