Skip to content

Commit

Permalink
add status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
benmmurphy committed Oct 29, 2010
1 parent 28b33a0 commit 211a24d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README
@@ -0,0 +1,9 @@
uses the javascript beautifier from jsbeautifier.org to beautify all http responses with the mime type text/javascript or application/javascript.

WARNING: this plugin is applied globally and may screw up your web browsing session.

KNOWN ISSUES
------------

* doesn't handle character encoding properly
* weird errors when calling 'this.originalListener.onStartRequest(request, context);'
3 changes: 3 additions & 0 deletions chrome/content/firefoxOverlay.xul
@@ -1,4 +1,7 @@
<overlay id="jsbeautifier"
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"/>
</statusbar>
</overlay>
26 changes: 24 additions & 2 deletions chrome/content/module.js
@@ -1,6 +1,27 @@
var EXPORTED_SYMBOLS = ["jsbeautifier"];

var jsbeautifier = {};
var jsbeautifier = {active:false, listeners: []};

jsbeautifier.addListener = function(l) {
this.listeners.push(l);
};

jsbeautifier.removeListener = function(l) {
var i = this.listeners.indexOf(l);
if (i < 0) {
return;
}
Components.utils.reportError("removing listener: " + i);
this.listeners.splice(i, 1);
Components.utils.reportError("listeners: " + this.listeners);
};

jsbeautifier.toggle = function() {
this.active = !this.active;
for (var i = 0; i < this.listeners.length; ++i) {
this.listeners[i]();
}
};

var jsb = function() {

Expand All @@ -12,7 +33,8 @@ var jsb = function() {

var httpRequestObserver = {
observe: function(subject, topic, data) {
if (topic == 'http-on-examine-response' || topic == 'http-on-examine-cached-response') {

if (jsbeautifier.active && (topic == 'http-on-examine-response' || topic == 'http-on-examine-cached-response')) {
if (subject instanceof Components.interfaces.nsIHttpChannel) {
var newListener = new JSBeautifierListener();
subject.QueryInterface(Ci.nsITraceableChannel);
Expand Down
24 changes: 22 additions & 2 deletions chrome/content/overlay.js
@@ -1,3 +1,23 @@

Components.utils.import("resource://modules/module.js");
jsbeautifier.Worker = Worker;
jsbeautifier.Worker = Worker;

function update_text() {
document.getElementById("jsbStatus").label = jsbeautifier.active ? "JSB ON" : "JSB OFF";
};

function toggle() {
jsbeautifier.toggle();
};

function load() {
update_text();
jsbeautifier.addListener(update_text);
document.getElementById("jsbStatus").addEventListener("click", toggle, false);
};

function unload() {
jsbeautifier.removeListener(update_text);
};

window.addEventListener("load", load, false);
window.addEventListener("unload", unload, false);

0 comments on commit 211a24d

Please sign in to comment.