--- chrome/chromeFiles/content/browser.js 2005-12-01 04:03:36.000000000 +0000 +++ chrome/chromeFiles/content/browser.js 2006-02-10 13:22:30.000000000 +0000 @@ -66,8 +66,11 @@ // listen for clicks on the install bar Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService) .addObserver(this, "install-userscript", true); + Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService) + .addObserver(this, "view-source", true); // we use this to determine if we are the active window sometimes this.winWat = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] .getService(Components.interfaces.nsIWindowWatcher); @@ -153,27 +156,41 @@ GM_listen(unsafeWin, "pagehide", GM_hitch(this, "contentUnload")); } - if (GM_getEnabled() && href.match(/\.user\.js($|\?)/i)) { + if (GM_getEnabled() && href.match(/\.user\.js($|\?)/i) && !href.match(/^view-source:/i)) { // find the browser the user script is loading in for (var i = 0, browser; browser = this.tabBrowser.browsers[i]; i++) { if (browser.contentWindow == unsafeWin) { var pick = Math.round(Math.random() * (GM_BrowserUI.greetz.length - 1)); var greeting = GM_BrowserUI.greetz[pick]; - this.tabBrowser.showMessage( - browser, - "chrome://greasemonkey/content/status_on.gif", - greeting + " This is a Greasemonkey User Script. " + - "Click Install to start using it.", - "Install", - null /* default doc shell */, - "install-userscript", - null /* no popuup */, - "top", - true /* show close button */, - "I" /* access key */); + if (unsafeWin.document.contentType.match(/^(text\/plain|application\/(x-)?javascript)$/i)) { + this.tabBrowser.showMessage( + browser, + "chrome://greasemonkey/content/status_on.gif", + greeting + " This is a Greasemonkey User Script. " + + "Click Install to start using it.", + "Install", + null /* default doc shell */, + "install-userscript", + null /* no popuup */, + "top", + true /* show close button */, + "I" /* access key */); + } else { + this.tabBrowser.showMessage( + browser, + "chrome://greasemonkey/content/status_off.gif", + greeting + " " + "This User Script is not plain text so it cannot be installed.", + "View Source", + null /* default doc shell */, + "view-source", + null /* no popup */, + "top", + true /* show close button */, + null /* access key */); + } break; } } @@ -189,8 +206,13 @@ if (window == this.winWat.activeWindow) { new ScriptDownloader().installFromURL( this.tabBrowser.selectedBrowser.contentWindow.location.href); } + } else if (topic == "view-source") { + if (window == this.winWat.activeWindow) { + this.tabBrowser.selectedBrowser.contentWindow.location.replace("view-source:" + + this.tabBrowser.selectedBrowser.contentWindow.location.href); + } } else { throw new Error("Unexpected topic received: {" + topic + "}"); } }