Index: chrome/chromeFiles/content/browser.js =================================================================== RCS file: /cvs/greasemonkey/src/chrome/chromeFiles/content/browser.js,v retrieving revision 1.5 diff -U4 -r1.5 browser.js --- chrome/chromeFiles/content/browser.js 9 Jan 2006 10:07:55 -0000 1.5 +++ chrome/chromeFiles/content/browser.js 10 Feb 2006 13:27:10 -0000 @@ -69,8 +69,9 @@ "DOMContentLoaded", this.handleContentLoad, false); // listen for clicks on the install bar this.obsSvc.addObserver(this, "install-userscript", false); + this.obsSvc.addObserver(this, "view-source", false); // update enabled icon this.refreshStatus(); } @@ -81,8 +82,9 @@ */ GM_BrowserUI.prototype.handleWinUnload = function(e) { // remove install bar obsrever this.obsSvc.removeObserver(this, "install-userscript"); + this.obsSvc.removeObserver(this, "view-script"); GM_prefRoot.unwatch("enabled", this.refreshStatus); } @@ -100,26 +102,40 @@ for(var i = 0; i < 6; i++){ this.greetz.push(this.bundle.getString('greetz.' + i)); } - if (GM_getEnabled() && win.location.pathname.match(/\.user\.js$/i)) { + if (GM_getEnabled() && win.location.pathname.match(/\.user\.js$/i) && win.location.protocol != "view-source:")) { // find the browser the user script is loading in for (var i = 0, browser; browser = this.tabBrowser.browsers[i]; i++) { if (browser.contentWindow == win) { var pick = Math.round(Math.random() * (this.greetz.length - 1)); var greeting = this.greetz[pick]; - this.tabBrowser.showMessage( - browser, - "chrome://greasemonkey/content/status_on.gif", - greeting + " " + this.bundle.getString('greeting.msg'), - this.bundle.getString('greeting.btn'), - null /* default doc shell */, - "install-userscript", - null /* no popuup */, - "top", - true /* show close button */, - "I" /* access key */); + if (win.document.contentType.match(/^(text\/plain|application\/(x-)?javascript)$/)) { + this.tabBrowser.showMessage( + browser, + "chrome://greasemonkey/content/status_on.gif", + greeting + " " + this.bundle.getString('greeting.msg'), + this.bundle.getString('greeting.btn'), + 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.bundle.getString('warning.msg'), + this.bundle.getString('warning.btn'), + null /* default doc shell */, + "view-source", + null /* no popup */, + "top", + true /* show close button */, + null /* access key */); + } break; } } @@ -196,8 +212,13 @@ if (this.win == this.winWat.activeWindow) { new ScriptDownloader(this).installFromURL( this.tabBrowser.selectedBrowser.contentWindow.location.href); } + } else if (topic == "view-source") { + if (this.win == 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 + "}"); } } Index: chrome/chromeFiles/locale/en-US/gm-browser.properties =================================================================== RCS file: /cvs/greasemonkey/src/chrome/chromeFiles/locale/en-US/gm-browser.properties,v retrieving revision 1.1 diff -U4 -r1.1 gm-browser.properties --- chrome/chromeFiles/locale/en-US/gm-browser.properties 5 Jan 2006 13:22:57 -0000 1.1 +++ chrome/chromeFiles/locale/en-US/gm-browser.properties 10 Feb 2006 13:27:11 -0000 @@ -6,8 +6,10 @@ tooltip.enabled=Greasemonkey is enabled. greeting.msg=This is a Greasemonkey User Script. Click Install to start using it. greeting.btn=Install +warning.msg=This User Script is not plain text so it cannot be installed. +warning.btn=View Source greetz.0=Huzzah! greetz.1=Toodles... greetz.2=Howdy!