浏览代码

improved loading urls ending with .user.js

Gerald 12 年之前
父节点
当前提交
26e863da38
共有 7 个文件被更改,包括 63 次插入95 次删除
  1. 8 12
      _locales/cs/messages.json
  2. 8 12
      _locales/en/messages.json
  3. 8 12
      _locales/pl/messages.json
  4. 8 12
      _locales/ru/messages.json
  5. 9 13
      _locales/zh/messages.json
  6. 11 13
      background.js
  7. 11 21
      confirm.js

+ 8 - 12
_locales/cs/messages.json

@@ -11,10 +11,6 @@
 		"message": "ahoj1234", 
 		"message": "ahoj1234", 
 		"description": "Information of the translator."
 		"description": "Information of the translator."
 	}, 
 	}, 
-	"defaultSearch": {
-		"message": "http://www.google.com/search?q=*", 
-		"description": "URL for searching scripts, * stands for the keywords."
-	}, 
 	"msgUpdated": {
 	"msgUpdated": {
 		"message": "Skript aktualizován.", 
 		"message": "Skript aktualizován.", 
 		"description": "Message shown when a script is updated/reinstalled."
 		"description": "Message shown when a script is updated/reinstalled."
@@ -27,6 +23,10 @@
 		"message": "Skript nainstalován.", 
 		"message": "Skript nainstalován.", 
 		"description": "Message shown when a script is installed."
 		"description": "Message shown when a script is installed."
 	}, 
 	}, 
+	"defaultSearch": {
+		"message": "http://www.google.com/search?q=*", 
+		"description": "URL for searching scripts, * stands for the keywords."
+	}, 
 	"msgUpdating": {
 	"msgUpdating": {
 		"message": "Aktualizuji...", 
 		"message": "Aktualizuji...", 
 		"description": "Message shown when a new version of script is being fetched."
 		"description": "Message shown when a new version of script is being fetched."
@@ -75,14 +75,6 @@
 		"message": "Design od <a href=mailto:[email protected]>Gerald</a>, Přeložil: <a href=http://my.opera.com/ahoj1234 target=_blank>ahoj1234</a>", 
 		"message": "Design od <a href=mailto:[email protected]>Gerald</a>, Přeložil: <a href=http://my.opera.com/ahoj1234 target=_blank>ahoj1234</a>", 
 		"description": "Author shown in the footer of options page, translator information may be added."
 		"description": "Author shown in the footer of options page, translator information may be added."
 	}, 
 	}, 
-	"msgNotJS": {
-		"message": "URL vypadá, že není Javascript. Bude načteno přímo za 3 sekundy.", 
-		"description": "Message shown in the confirm page when loading a URL ends with .user.js but seems not to be Javascript. It will then be loaded again directly in 3 seconds."
-	}, 
-	"msgLoadedJS": {
-		"message": "Javascript načten: $1", 
-		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
-	}, 
 	"msgErrorLoadingURL": {
 	"msgErrorLoadingURL": {
 		"message": "Chyba načítání URL: $1", 
 		"message": "Chyba načítání URL: $1", 
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
@@ -91,6 +83,10 @@
 		"message": "Načítání URL: $1", 
 		"message": "Načítání URL: $1", 
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 	}, 
 	}, 
+	"msgLoadedJS": {
+		"message": "Javascript načten: $1", 
+		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
+	}, 
 	"labelOptions": {
 	"labelOptions": {
 		"message": "Možnosti", 
 		"message": "Možnosti", 
 		"description": "Options of this extension."
 		"description": "Options of this extension."

+ 8 - 12
_locales/en/messages.json

@@ -11,10 +11,6 @@
 		"message": "Gerald <[email protected]>", 
 		"message": "Gerald <[email protected]>", 
 		"description": "Information of the translator."
 		"description": "Information of the translator."
 	}, 
 	}, 
-	"defaultSearch": {
-		"message": "http://www.google.com/search?q=*", 
-		"description": "URL for searching scripts, * stands for the keywords."
-	}, 
 	"msgUpdated": {
 	"msgUpdated": {
 		"message": "Script updated.", 
 		"message": "Script updated.", 
 		"description": "Message shown when a script is updated/reinstalled."
 		"description": "Message shown when a script is updated/reinstalled."
@@ -27,6 +23,10 @@
 		"message": "Script installed.", 
 		"message": "Script installed.", 
 		"description": "Message shown when a script is installed."
 		"description": "Message shown when a script is installed."
 	}, 
 	}, 
+	"defaultSearch": {
+		"message": "http://www.google.com/search?q=*", 
+		"description": "URL for searching scripts, * stands for the keywords."
+	}, 
 	"msgUpdating": {
 	"msgUpdating": {
 		"message": "Updating...", 
 		"message": "Updating...", 
 		"description": "Message shown when a new version of script is being fetched."
 		"description": "Message shown when a new version of script is being fetched."
@@ -75,14 +75,6 @@
 		"message": "Designed by <a href=mailto:[email protected]>Gerald</a>", 
 		"message": "Designed by <a href=mailto:[email protected]>Gerald</a>", 
 		"description": "Author shown in the footer of options page, translator information may be added."
 		"description": "Author shown in the footer of options page, translator information may be added."
 	}, 
 	}, 
-	"msgNotJS": {
-		"message": "URL seems not to be Javascript. It will be loaded directly in 3 seconds.", 
-		"description": "Message shown in the confirm page when loading a URL ends with .user.js but seems not to be Javascript. It will then be loaded again directly in 3 seconds."
-	}, 
-	"msgLoadedJS": {
-		"message": "Javascript loaded: $1", 
-		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
-	}, 
 	"msgErrorLoadingURL": {
 	"msgErrorLoadingURL": {
 		"message": "Error loading URL: $1", 
 		"message": "Error loading URL: $1", 
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
@@ -91,6 +83,10 @@
 		"message": "Loading URL: $1", 
 		"message": "Loading URL: $1", 
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 	}, 
 	}, 
+	"msgLoadedJS": {
+		"message": "Javascript loaded: $1", 
+		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
+	}, 
 	"labelOptions": {
 	"labelOptions": {
 		"message": "Options", 
 		"message": "Options", 
 		"description": "Options of this extension."
 		"description": "Options of this extension."

+ 8 - 12
_locales/pl/messages.json

@@ -11,10 +11,6 @@
 		"message": "MISI90 <[email protected]>", 
 		"message": "MISI90 <[email protected]>", 
 		"description": "Information of the translator."
 		"description": "Information of the translator."
 	}, 
 	}, 
-	"defaultSearch": {
-		"message": "http://www.google.com/search?q=*", 
-		"description": "URL for searching scripts, * stands for the keywords."
-	}, 
 	"msgUpdated": {
 	"msgUpdated": {
 		"message": "Skrypt zaktualizowany.", 
 		"message": "Skrypt zaktualizowany.", 
 		"description": "Message shown when a script is updated/reinstalled."
 		"description": "Message shown when a script is updated/reinstalled."
@@ -27,6 +23,10 @@
 		"message": "Skrypt zainstalowany", 
 		"message": "Skrypt zainstalowany", 
 		"description": "Message shown when a script is installed."
 		"description": "Message shown when a script is installed."
 	}, 
 	}, 
+	"defaultSearch": {
+		"message": "http://www.google.com/search?q=*", 
+		"description": "URL for searching scripts, * stands for the keywords."
+	}, 
 	"msgUpdating": {
 	"msgUpdating": {
 		"message": "Aktualizowanie...", 
 		"message": "Aktualizowanie...", 
 		"description": "Message shown when a new version of script is being fetched."
 		"description": "Message shown when a new version of script is being fetched."
@@ -75,14 +75,6 @@
 		"message": "Stworzone przez <a href=mailto:[email protected]>Gerald</a>, tłumaczenie MISI90", 
 		"message": "Stworzone przez <a href=mailto:[email protected]>Gerald</a>, tłumaczenie MISI90", 
 		"description": "Author shown in the footer of options page, translator information may be added."
 		"description": "Author shown in the footer of options page, translator information may be added."
 	}, 
 	}, 
-	"msgNotJS": {
-		"message": "Adres URL nie wygląda na Javascript. Będzie załadowany bezpośrednio za 3 sekundy.", 
-		"description": "Message shown in the confirm page when loading a URL ends with .user.js but seems not to be Javascript. It will then be loaded again directly in 3 seconds."
-	}, 
-	"msgLoadedJS": {
-		"message": "Javascript załadowany: $1", 
-		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
-	}, 
 	"msgErrorLoadingURL": {
 	"msgErrorLoadingURL": {
 		"message": "Błąd ładowania URL: $1", 
 		"message": "Błąd ładowania URL: $1", 
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
@@ -91,6 +83,10 @@
 		"message": "Ładowanie URL: $1", 
 		"message": "Ładowanie URL: $1", 
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 	}, 
 	}, 
+	"msgLoadedJS": {
+		"message": "Javascript załadowany: $1", 
+		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
+	}, 
 	"labelOptions": {
 	"labelOptions": {
 		"message": "Opcje", 
 		"message": "Opcje", 
 		"description": "Options of this extension."
 		"description": "Options of this extension."

+ 8 - 12
_locales/ru/messages.json

@@ -11,10 +11,6 @@
 		"message": "softovikk", 
 		"message": "softovikk", 
 		"description": "Information of the translator."
 		"description": "Information of the translator."
 	}, 
 	}, 
-	"defaultSearch": {
-		"message": "http://www.google.com/search?q=*", 
-		"description": "URL for searching scripts, * stands for the keywords."
-	}, 
 	"msgUpdated": {
 	"msgUpdated": {
 		"message": "Скрипт обновлен.", 
 		"message": "Скрипт обновлен.", 
 		"description": "Message shown when a script is updated/reinstalled."
 		"description": "Message shown when a script is updated/reinstalled."
@@ -27,6 +23,10 @@
 		"message": "Скрипт установлен.", 
 		"message": "Скрипт установлен.", 
 		"description": "Message shown when a script is installed."
 		"description": "Message shown when a script is installed."
 	}, 
 	}, 
+	"defaultSearch": {
+		"message": "http://www.google.com/search?q=*", 
+		"description": "URL for searching scripts, * stands for the keywords."
+	}, 
 	"msgUpdating": {
 	"msgUpdating": {
 		"message": "Обновление...", 
 		"message": "Обновление...", 
 		"description": "Message shown when a new version of script is being fetched."
 		"description": "Message shown when a new version of script is being fetched."
@@ -75,14 +75,6 @@
 		"message": "Разработано <a href=mailto:[email protected]>Gerald</a>", 
 		"message": "Разработано <a href=mailto:[email protected]>Gerald</a>", 
 		"description": "Author shown in the footer of options page, translator information may be added."
 		"description": "Author shown in the footer of options page, translator information may be added."
 	}, 
 	}, 
-	"msgNotJS": {
-		"message": "URL seems not to be Javascript. It will be loaded directly in 3 seconds.", 
-		"description": "Message shown in the confirm page when loading a URL ends with .user.js but seems not to be Javascript. It will then be loaded again directly in 3 seconds."
-	}, 
-	"msgLoadedJS": {
-		"message": "Javascript loaded: $1", 
-		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
-	}, 
 	"msgErrorLoadingURL": {
 	"msgErrorLoadingURL": {
 		"message": "Error loading URL: $1", 
 		"message": "Error loading URL: $1", 
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
@@ -91,6 +83,10 @@
 		"message": "Loading URL: $1", 
 		"message": "Loading URL: $1", 
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 	}, 
 	}, 
+	"msgLoadedJS": {
+		"message": "Javascript loaded: $1", 
+		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
+	}, 
 	"labelOptions": {
 	"labelOptions": {
 		"message": "Опции", 
 		"message": "Опции", 
 		"description": "Options of this extension."
 		"description": "Options of this extension."

+ 9 - 13
_locales/zh/messages.json

@@ -11,10 +11,6 @@
 		"message": "Gerald <[email protected]>", 
 		"message": "Gerald <[email protected]>", 
 		"description": "Information of the translator."
 		"description": "Information of the translator."
 	}, 
 	}, 
-	"defaultSearch": {
-		"message": "http://www.baidu.com/s?wd=*", 
-		"description": "URL for searching scripts, * stands for the keywords."
-	}, 
 	"msgUpdated": {
 	"msgUpdated": {
 		"message": "脚本已更新。", 
 		"message": "脚本已更新。", 
 		"description": "Message shown when a script is updated/reinstalled."
 		"description": "Message shown when a script is updated/reinstalled."
@@ -27,6 +23,10 @@
 		"message": "脚本已安装。", 
 		"message": "脚本已安装。", 
 		"description": "Message shown when a script is installed."
 		"description": "Message shown when a script is installed."
 	}, 
 	}, 
+	"defaultSearch": {
+		"message": "http://www.baidu.com/s?wd=*", 
+		"description": "URL for searching scripts, * stands for the keywords."
+	}, 
 	"msgUpdating": {
 	"msgUpdating": {
 		"message": "正在更新...", 
 		"message": "正在更新...", 
 		"description": "Message shown when a new version of script is being fetched."
 		"description": "Message shown when a new version of script is being fetched."
@@ -75,14 +75,6 @@
 		"message": "<a href=mailto:[email protected]>Gerald</a> 制作", 
 		"message": "<a href=mailto:[email protected]>Gerald</a> 制作", 
 		"description": "Author shown in the footer of options page, translator information may be added."
 		"description": "Author shown in the footer of options page, translator information may be added."
 	}, 
 	}, 
-	"msgNotJS": {
-		"message": "链接似乎不是Javascript,将在3秒后直接打开。", 
-		"description": "Message shown in the confirm page when loading a URL ends with .user.js but seems not to be Javascript. It will then be loaded again directly in 3 seconds."
-	}, 
-	"msgLoadedJS": {
-		"message": "Javascript已加载:$1", 
-		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
-	}, 
 	"msgErrorLoadingURL": {
 	"msgErrorLoadingURL": {
 		"message": "链接打开发生错误:$1", 
 		"message": "链接打开发生错误:$1", 
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
 		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
@@ -91,6 +83,10 @@
 		"message": "正在打开链接:$1", 
 		"message": "正在打开链接:$1", 
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 		"description": "Message shown in the confirm page when a URL of a script is being loaded."
 	}, 
 	}, 
+	"msgLoadedJS": {
+		"message": "Javascript已加载:$1", 
+		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
+	}, 
 	"labelOptions": {
 	"labelOptions": {
 		"message": "选项", 
 		"message": "选项", 
 		"description": "Options of this extension."
 		"description": "Options of this extension."
@@ -355,4 +351,4 @@
 		"message": "所有", 
 		"message": "所有", 
 		"description": "Button to replace all matches."
 		"description": "Button to replace all matches."
 	}
 	}
-}
+}

+ 11 - 13
background.js

@@ -572,7 +572,6 @@ chrome.runtime.onMessage.addListener(function(req,src,callback) {
 		AutoUpdate: autoUpdate,
 		AutoUpdate: autoUpdate,
 		Vacuum: vacuum,
 		Vacuum: vacuum,
 		Move: move,
 		Move: move,
-		LoadDirectly:loadDirectly,
 	},f=maps[req.cmd];
 	},f=maps[req.cmd];
 	if(f) f(req.data,src,callback);
 	if(f) f(req.data,src,callback);
 	return true;
 	return true;
@@ -587,19 +586,18 @@ initDb(function(){
 	chrome.browserAction.setIcon({path:'images/icon19'+(settings.isApplied?'':'w')+'.png'});
 	chrome.browserAction.setIcon({path:'images/icon19'+(settings.isApplied?'':'w')+'.png'});
 	setTimeout(autoCheck,2e4);
 	setTimeout(autoCheck,2e4);
 });
 });
-var directUrls={};
-function loadDirectly(o,src,callback){
-	directUrls[o]=1;
-	if(callback) callback();
-}
 chrome.webRequest.onBeforeRequest.addListener(function(o){
 chrome.webRequest.onBeforeRequest.addListener(function(o){
-	if(directUrls[o.url]) delete directUrls[o.url];
-	else if(/\.user\.js(\?|$)/.test(o.url)) {
-		if(o.tabId<0) chrome.tabs.create({url:chrome.extension.getURL('/confirm.html')+'?url='+encodeURIComponent(o.url)});
-		else chrome.tabs.get(o.tabId,function(t){
-			chrome.tabs.create({url:chrome.extension.getURL('/confirm.html')+'?url='+encodeURIComponent(o.url)+'&from='+encodeURIComponent(t.url)});
-		});
-		return {redirectUrl:'javascript:history.back()'};
+	if(/\.user\.js(\?|$)/.test(o.url)) {
+		var x=new XMLHttpRequest();
+		x.open('GET',o.url,false);
+		x.send();
+		if((!x.status||x.status==200)&&/^\s*[^<]/.test(x.responseText)) {
+			if(o.tabId<0) chrome.tabs.create({url:chrome.extension.getURL('/confirm.html')+'?url='+encodeURIComponent(o.url)});
+			else chrome.tabs.get(o.tabId,function(t){
+				chrome.tabs.create({url:chrome.extension.getURL('/confirm.html')+'?url='+encodeURIComponent(o.url)+'&from='+encodeURIComponent(t.url)});
+			});
+			return {redirectUrl:'javascript:history.back()'};
+		}
 	}
 	}
 },{
 },{
 	urls:['*://*/*','file://*/*'],types:['main_frame']
 	urls:['*://*/*','file://*/*'],types:['main_frame']

+ 11 - 21
confirm.js

@@ -1,15 +1,3 @@
-function checkScript(t){
-	if(/^\s*</.test(t)) {	// seems to be HTML code
-		M.innerHTML=_('msgNotJS',[data.url]);
-		chrome.runtime.sendMessage({cmd:'LoadDirectly',data:data.url},function(){
-			setTimeout(function(){location.replace(data.url);},3000);
-		});
-	} else {	// may be JS code
-		M.innerHTML=_('msgLoadedJS',[data.url]);
-		T.setValueAndFocus(t);
-		I.disabled=false;
-	}
-}
 var $=document.getElementById.bind(document),M=$('msg'),I=$('bInstall'),data={},
 var $=document.getElementById.bind(document),M=$('msg'),I=$('bInstall'),data={},
 		B=$('bClose'),C=$('cClose'),T;
 		B=$('bClose'),C=$('cClose'),T;
 B.onclick=function(){window.close();};
 B.onclick=function(){window.close();};
@@ -27,8 +15,6 @@ I.onclick=function(){
 	});
 	});
 	I.disabled=true;
 	I.disabled=true;
 };
 };
-initEditor(function(o){T=o;},{exit:B.onclick,readonly:true});
-initCSS();initI18n(function(){document.body.classList.remove('hide');});
 chrome.runtime.onMessage.addListener(function(req,src,callback) {
 chrome.runtime.onMessage.addListener(function(req,src,callback) {
 	var maps={
 	var maps={
 		ShowMessage: function(o){
 		ShowMessage: function(o){
@@ -40,10 +26,10 @@ chrome.runtime.onMessage.addListener(function(req,src,callback) {
 	if(f) f(req.data,src,callback);
 	if(f) f(req.data,src,callback);
 	return true;
 	return true;
 });
 });
-chrome.runtime.sendMessage({cmd:'GetOption',data:'closeAfterInstall'},function(o){
-	C.checked=!!o;
-	var s=location.search.slice(1);
-	s.split('&').forEach(function(i){
+chrome.runtime.sendMessage({cmd:'GetOption',data:'closeAfterInstall'},function(o){C.checked=!!o;});
+initEditor(function(o){
+	T=o;o=location.search.slice(1);
+	o.split('&').forEach(function(i){
 		i.replace(/^([^=]*)=(.*)$/,function(r,g1,g2){data[g1]=decodeURIComponent(g2);});
 		i.replace(/^([^=]*)=(.*)$/,function(r,g1,g2){data[g1]=decodeURIComponent(g2);});
 	});
 	});
 	function error(){M.innerHTML=_('msgErrorLoadingURL',[data.url]);}
 	function error(){M.innerHTML=_('msgErrorLoadingURL',[data.url]);}
@@ -52,9 +38,13 @@ chrome.runtime.sendMessage({cmd:'GetOption',data:'closeAfterInstall'},function(o
 		var x=new XMLHttpRequest();
 		var x=new XMLHttpRequest();
 		x.open('GET',data.url,true);
 		x.open('GET',data.url,true);
 		x.onloadend=function(){
 		x.onloadend=function(){
-			if((!this.status||this.status==200)&&this.responseText) checkScript(this.responseText);
-			else error();
+			if((!this.status||this.status==200)&&this.responseText) {
+				M.innerHTML=_('msgLoadedJS',[data.url]);
+				T.setValueAndFocus(this.responseText);
+				I.disabled=false;
+			} else error();
 		};
 		};
 		x.send();
 		x.send();
 	}
 	}
-});
+},{exit:B.onclick,readonly:true});
+initCSS();initI18n(function(){document.body.classList.remove('hide');});