Explorar o código

load requirements before confirming installation

Gerald %!s(int64=12) %!d(string=hai) anos
pai
achega
d1fd26ae9e
Modificáronse 9 ficheiros con 164 adicións e 74 borrados
  1. 25 13
      _locales/cs/messages.json
  2. 20 8
      _locales/en/messages.json
  3. 26 14
      _locales/pl/messages.json
  4. 30 18
      _locales/ru/messages.json
  5. 19 7
      _locales/zh/messages.json
  6. 11 5
      background.js
  7. 1 0
      common.css
  8. 1 1
      confirm.html
  9. 31 8
      confirm.js

+ 25 - 13
_locales/cs/messages.json

@@ -56,7 +56,7 @@
 		"description": "Shown in the title of the confirm page while trying to install a script."
 	},
 	"optionClose": {
-		"message": "Close after installation",
+		"message": "Close po instalaci",
 		"description": "Option to close confirm window after installation."
 	},
 	"buttonConfirmInstallation": {
@@ -75,18 +75,30 @@
 		"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."
 	},
-	"msgErrorLoadingURL": {
-		"message": "Chyba načítání URL: $1",
-		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
+	"msgScriptURL": {
+		"message": "Skript URL: $1",
+		"description": "URL of the script to be installed on confirm page."
 	},
-	"msgLoadingURL": {
-		"message": "Načítání URL: $1",
-		"description": "Message shown in the confirm page when a URL of a script is being loaded."
+	"msgLoadingJS": {
+		"message": "Nahrávám skript...",
+		"description": "Message shown on confirm page when the script to be installed is loading."
+	},
+	"msgLoadingRequirements": {
+		"message": "Vkládání požadavky... ($1/$2)",
+		"description": "Message shown on confirm page when the requirements are being downloaded."
+	},
+	"msgErrorLoadingRequirements": {
+		"message": "Chyba při načítání požadavky.",
+		"description": "Message shown when not all requirements are loaded successfully."
 	},
 	"msgLoadedJS": {
-		"message": "Javascript načten: $1",
+		"message": "Skript načten.",
 		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
 	},
+	"msgErrorLoadingJS": {
+		"message": "Chyba při načítání skript.",
+		"description": "Message shown on confirm page when the script to be installed cannot be loaded."
+	},
 	"labelOptions": {
 		"message": "Možnosti",
 		"description": "Options of this extension."
@@ -336,19 +348,19 @@
 		"description": "Menu item to list script commands."
 	},
 	"labelSearch": {
-		"message": "Search for: ",
+		"message": "Hledat: ",
 		"description": "Label for search input in search box."
 	},
 	"labelReplace": {
-		"message": "Replace with: ",
+		"message": "Nahradit: ",
 		"description": "Label for replace input in search box."
 	},
 	"buttonReplace": {
-		"message": "Replace",
+		"message": "Nahradit",
 		"description": "Button to replace the current match."
 	},
 	"buttonReplaceAll": {
-		"message": "All",
+		"message": "Vše",
 		"description": "Button to replace all matches."
 	}
-}
+}

+ 20 - 8
_locales/en/messages.json

@@ -75,18 +75,30 @@
 		"message": "Designed by <a href=mailto:[email protected]>Gerald</a>",
 		"description": "Author shown in the footer of options page, translator information may be added."
 	},
-	"msgErrorLoadingURL": {
-		"message": "Error loading URL: $1",
-		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
+	"msgScriptURL": {
+		"message": "Script URL: $1",
+		"description": "URL of the script to be installed on confirm page."
 	},
-	"msgLoadingURL": {
-		"message": "Loading URL: $1",
-		"description": "Message shown in the confirm page when a URL of a script is being loaded."
+	"msgLoadingJS": {
+		"message": "Loading script...",
+		"description": "Message shown on confirm page when the script to be installed is loading."
+	},
+	"msgLoadingRequirements": {
+		"message": "Loading requirements... ($1/$2)",
+		"description": "Message shown on confirm page when the requirements are being downloaded."
+	},
+	"msgErrorLoadingRequirements": {
+		"message": "Error loading requirements.",
+		"description": "Message shown when not all requirements are loaded successfully."
 	},
 	"msgLoadedJS": {
-		"message": "Javascript loaded: $1",
+		"message": "Script loaded.",
 		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
 	},
+	"msgErrorLoadingJS": {
+		"message": "Error loading script.",
+		"description": "Message shown on confirm page when the script to be installed cannot be loaded."
+	},
 	"labelOptions": {
 		"message": "Options",
 		"description": "Options of this extension."
@@ -351,4 +363,4 @@
 		"message": "All",
 		"description": "Button to replace all matches."
 	}
-}
+}

+ 26 - 14
_locales/pl/messages.json

@@ -56,7 +56,7 @@
 		"description": "Shown in the title of the confirm page while trying to install a script."
 	},
 	"optionClose": {
-		"message": "Close after installation",
+		"message": "Zamknij po zakończeniu instalacji",
 		"description": "Option to close confirm window after installation."
 	},
 	"buttonConfirmInstallation": {
@@ -75,18 +75,30 @@
 		"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."
 	},
-	"msgErrorLoadingURL": {
-		"message": "Błąd ładowania URL: $1",
-		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
+	"msgScriptURL": {
+		"message": "Skrypt URL: $1",
+		"description": "URL of the script to be installed on confirm page."
 	},
-	"msgLoadingURL": {
-		"message": "Ładowanie URL: $1",
-		"description": "Message shown in the confirm page when a URL of a script is being loaded."
+	"msgLoadingJS": {
+		"message": "Skrypt ładowania...",
+		"description": "Message shown on confirm page when the script to be installed is loading."
+	},
+	"msgLoadingRequirements": {
+		"message": "Wymagania ładowania... ($1/$2)",
+		"description": "Message shown on confirm page when the requirements are being downloaded."
+	},
+	"msgErrorLoadingRequirements": {
+		"message": "Błąd podczas ładowania wymagania.",
+		"description": "Message shown when not all requirements are loaded successfully."
 	},
 	"msgLoadedJS": {
-		"message": "Javascript załadowany: $1",
+		"message": "Skrypt załadowany.",
 		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
 	},
+	"msgErrorLoadingJS": {
+		"message": "Błąd wczytywania skryptu.",
+		"description": "Message shown on confirm page when the script to be installed cannot be loaded."
+	},
 	"labelOptions": {
 		"message": "Opcje",
 		"description": "Options of this extension."
@@ -116,7 +128,7 @@
 		"description": "Option to show the details of scripts, such as author, description, etc."
 	},
 	"msgLoading": {
-		"message": "Loading ...",
+		"message": "Ładowanie ...",
 		"description": "Message shown in the options page before script list is loaded."
 	},
 	"labelScriptEditor": {
@@ -336,19 +348,19 @@
 		"description": "Menu item to list script commands."
 	},
 	"labelSearch": {
-		"message": "Search for: ",
+		"message": "Szukaj w: ",
 		"description": "Label for search input in search box."
 	},
 	"labelReplace": {
-		"message": "Replace with: ",
+		"message": "Zamień na: ",
 		"description": "Label for replace input in search box."
 	},
 	"buttonReplace": {
-		"message": "Replace",
+		"message": "Zastąpić",
 		"description": "Button to replace the current match."
 	},
 	"buttonReplaceAll": {
-		"message": "All",
+		"message": "Wszystko",
 		"description": "Button to replace all matches."
 	}
-}
+}

+ 30 - 18
_locales/ru/messages.json

@@ -52,15 +52,15 @@
 		"description": "Additional CSS for all pages."
 	},
 	"labelInstall": {
-		"message": "Installing script",
+		"message": "Установка сценария",
 		"description": "Shown in the title of the confirm page while trying to install a script."
 	},
 	"optionClose": {
-		"message": "Close after installation",
+		"message": "Закрыть после установки",
 		"description": "Option to close confirm window after installation."
 	},
 	"buttonConfirmInstallation": {
-		"message": "Confirm installation",
+		"message": "Подтвердите установку",
 		"description": "Button to confirm installation of a script."
 	},
 	"buttonClose": {
@@ -75,18 +75,30 @@
 		"message": "Разработано <a href=mailto:[email protected]>Gerald</a>",
 		"description": "Author shown in the footer of options page, translator information may be added."
 	},
-	"msgErrorLoadingURL": {
-		"message": "Error loading URL: $1",
-		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
+	"msgScriptURL": {
+		"message": "URL скрипта: $1",
+		"description": "URL of the script to be installed on confirm page."
 	},
-	"msgLoadingURL": {
-		"message": "Loading URL: $1",
-		"description": "Message shown in the confirm page when a URL of a script is being loaded."
+	"msgLoadingJS": {
+		"message": "Загрузка сценарий...",
+		"description": "Message shown on confirm page when the script to be installed is loading."
+	},
+	"msgLoadingRequirements": {
+		"message": "Загрузка требования... ($1/$2)",
+		"description": "Message shown on confirm page when the requirements are being downloaded."
+	},
+	"msgErrorLoadingRequirements": {
+		"message": "Требования к погрузке Ошибка.",
+		"description": "Message shown when not all requirements are loaded successfully."
 	},
 	"msgLoadedJS": {
-		"message": "Javascript loaded: $1",
+		"message": "Скрипт загружается.",
 		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
 	},
+	"msgErrorLoadingJS": {
+		"message": "Ошибка загрузки сценария.",
+		"description": "Message shown on confirm page when the script to be installed cannot be loaded."
+	},
 	"labelOptions": {
 		"message": "Опции",
 		"description": "Options of this extension."
@@ -276,7 +288,7 @@
 		"description": "Button to remove a script."
 	},
 	"labelNoName": {
-		"message": "Null name",
+		"message": "Без названия",
 		"description": "Text as the name of a script when no @name is assigned."
 	},
 	"labelAuthor": {
@@ -296,7 +308,7 @@
 		"description": "Message shown after import. There is an argument referring to the count of scripts imported."
 	},
 	"buttonVacuuming": {
-		"message": "Vacuuming data...",
+		"message": "Уборка пылесосом данных...",
 		"description": "Message shown when data vacuum is in progress."
 	},
 	"hintVacuumData": {
@@ -308,7 +320,7 @@
 		"description": "Button to confirm export."
 	},
 	"buttonExporting": {
-		"message": "Exporting data...",
+		"message": "Экспорт данных...",
 		"description": "Message shown when data export is in progress."
 	},
 	"buttonVacuumed": {
@@ -336,19 +348,19 @@
 		"description": "Menu item to list script commands."
 	},
 	"labelSearch": {
-		"message": "Search for: ",
+		"message": "Искать: ",
 		"description": "Label for search input in search box."
 	},
 	"labelReplace": {
-		"message": "Replace with: ",
+		"message": "Заменить на: ",
 		"description": "Label for replace input in search box."
 	},
 	"buttonReplace": {
-		"message": "Replace",
+		"message": "Заменять",
 		"description": "Button to replace the current match."
 	},
 	"buttonReplaceAll": {
-		"message": "All",
+		"message": "Все",
 		"description": "Button to replace all matches."
 	}
-}
+}

+ 19 - 7
_locales/zh/messages.json

@@ -75,18 +75,30 @@
 		"message": "<a href=mailto:[email protected]>Gerald</a> 制作",
 		"description": "Author shown in the footer of options page, translator information may be added."
 	},
-	"msgErrorLoadingURL": {
-		"message": "链接打开发生错误:$1",
-		"description": "Message shown in the confirm page when Violentmonkey failed to load the URL of a script."
+	"msgScriptURL": {
+		"message": "脚本URL:$1",
+		"description": "URL of the script to be installed on confirm page."
 	},
-	"msgLoadingURL": {
-		"message": "正在打开链接:$1",
-		"description": "Message shown in the confirm page when a URL of a script is being loaded."
+	"msgLoadingJS": {
+		"message": "正在加载脚本...",
+		"description": "Message shown on confirm page when the script to be installed is loading."
+	},
+	"msgLoadingRequirements": {
+		"message": "正在加载依赖脚本...($1/$2)",
+		"description": "Message shown on confirm page when the requirements are being downloaded."
+	},
+	"msgErrorLoadingRequirements": {
+		"message": "加载依赖脚本发生错误。",
+		"description": "Message shown when not all requirements are loaded successfully."
 	},
 	"msgLoadedJS": {
-		"message": "Javascript已加载:$1",
+		"message": "脚本已加载。",
 		"description": "Message shown in the confirm page when a javascript file to be installed is loaded."
 	},
+	"msgErrorLoadingJS": {
+		"message": "加载脚本发生错误。",
+		"description": "Message shown on confirm page when the script to be installed cannot be loaded."
+	},
 	"labelOptions": {
 		"message": "选项",
 		"description": "Options of this extension."

+ 11 - 5
background.js

@@ -283,13 +283,15 @@ function fetchCache(url) {
 		o.put({uri:url,data:this.response}).onsuccess=function(){delete _cache[url];};
 	}, 'arraybuffer');
 }
+function saveRequire(url,data,callback) {
+	var o=db.transaction('require','readwrite').objectStore('require');
+	o.put({uri:url,code:data}).onsuccess=callback;
+}
 function fetchRequire(url) {
 	if(_require[url]) return;
 	_require[url]=1;
-	fetchURL(url, function() {
-		if (this.status!=200) return;
-		var o=db.transaction('require','readwrite').objectStore('require');
-		o.put({uri:url,code:this.responseText}).onsuccess=function(){delete _require[url];};
+	fetchURL(url, function(){
+		if(this.status==200) saveRequire(url,this.responseText,function(){delete _require[url];});
 	});
 }
 function updateItem(r){
@@ -337,7 +339,10 @@ function parseScript(o,src,callback) {
 				r.id=c.id=e.target.result;r.obj=getMeta(c);finish();
 			};
 		});
-		meta.require.forEach(fetchRequire);	// @require
+		meta.require.forEach(function(u){	// @require
+			var c=o.require&&o.require[u];
+			if(c) saveRequire(u,c); else fetchRequire(u);
+		});
 		for(d in meta.resources) fetchCache(meta.resources[d]);	// @resource
 		if(meta.icon) fetchCache(meta.icon);	// @icon
 	}
@@ -574,6 +579,7 @@ chrome.runtime.onMessage.addListener(function(req,src,callback) {
 		AutoUpdate: autoUpdate,
 		Vacuum: vacuum,
 		Move: move,
+		ParseMeta: function(o,src,callback){callback(parseMeta(o));},
 	},f=maps[req.cmd];
 	if(f) f(req.data,src,callback);
 	return true;

+ 1 - 0
common.css

@@ -16,3 +16,4 @@ tr{vertical-align:top;padding:0;height:1px;}
 tr.expand{height:auto;}
 .expandr{position:relative;}
 .expanda{position:absolute;width:100%;height:100%;}
+td.right{text-align:right;}

+ 1 - 1
confirm.html

@@ -17,7 +17,7 @@
 					<button id=bClose data-i18n=buttonClose></button>
 				</td>
 			</tr>
-			<tr><td colspan=2 id=msg>&nbsp;</td></tr>
+			<tr><td id=url class=ellipsis>&nbsp;</td><td id=msg class="ellipsis right"></td></tr>
 			<tr class=expand><td id=eCode colspan=2 class=expandr></td></tr>
 			<tr><td colspan=2 class=center><span data-i18n=anchorSupportPage></span> - <span data-i18n=anchorAuthor></span> - 2013</td></tr>
 		</table>

+ 31 - 8
confirm.js

@@ -1,5 +1,6 @@
 var $=document.getElementById.bind(document),M=$('msg'),I=$('bInstall'),data={},
-		B=$('bClose'),C=$('cClose'),T;
+		U=$('url'),B=$('bClose'),C=$('cClose'),T;
+function showMsg(m,t){M.innerHTML=m;M.setAttribute('title',t||m);}
 B.onclick=function(){window.close();};
 C.onchange=function(){
 	chrome.runtime.sendMessage({cmd:'SetOption',data:{key:'closeAfterInstall',value:C.checked}});
@@ -11,6 +12,7 @@ I.onclick=function(){
 			url:data.url,
 			from:data.from,
 			code:T.getValue(),
+			require:data.require,
 		},
 	});
 	I.disabled=true;
@@ -18,7 +20,7 @@ I.onclick=function(){
 chrome.runtime.onMessage.addListener(function(req,src,callback) {
 	var maps={
 		ShowMessage: function(o){
-			M.innerHTML=o.message;
+			showMsg(o.message);
 			if(callback) callback();
 			if(o.status>=0&&C.checked) window.close();
 		},
@@ -32,17 +34,38 @@ initEditor(function(o){
 	o.split('&').forEach(function(i){
 		i.replace(/^([^=]*)=(.*)$/,function(r,g1,g2){data[g1]=decodeURIComponent(g2);});
 	});
-	function error(){M.innerHTML=_('msgErrorLoadingURL',[data.url]);}
-	if(!data.url) error(); else {
-		M.innerHTML=_('msgLoadingURL',[data.url]);
+	U.innerHTML=_('msgScriptURL',[data.url||'-']);
+	if(data.url) {
+		U.setAttribute('title',data.url);
+		showMsg(_('msgLoadingJS'));
 		var x=new XMLHttpRequest();
 		x.open('GET',data.url,true);
 		x.onloadend=function(){
 			if((!this.status||this.status==200)&&this.responseText) {
-				M.innerHTML=_('msgLoadedJS',[data.url]);
 				T.setValueAndFocus(this.responseText);
-				I.disabled=false;
-			} else error();
+				chrome.runtime.sendMessage({cmd:'ParseMeta',data:this.responseText},function(o){
+					var i=0,l=o.require.length,err=[];
+					showMsg(_('msgLoadingRequirements',[i,l]));
+					data.require={};
+					o.require.forEach(function(u){
+						var x=new XMLHttpRequest();
+						x.open('GET',u,true);
+						x.onloadend=function(){
+							i++;
+							if(this.status==200) data.require[u]=this.responseText;
+							else err.push(u);
+							if(i>=l) {
+								if(err.length) showMsg(_('msgErrorLoadingRequirements'),err.join('\n'));
+								else {
+									showMsg(_('msgLoadedJS'));
+									I.disabled=false;
+								}
+							}
+						};
+						x.send();
+					});
+				});
+			} else showMsg(_('msgErrorLoadingJS'));
 		};
 		x.send();
 	}