Browse Source

added support for `@name` and `@description` in specific locales

Signed-off-by: Gerald <[email protected]>
Gerald 11 years ago
parent
commit
cb1307ebab
5 changed files with 17 additions and 6 deletions
  1. 1 1
      background.js
  2. 10 0
      common.js
  3. 1 1
      manifest.json
  4. 3 3
      options.js
  5. 2 1
      popup.js

+ 1 - 1
background.js

@@ -645,7 +645,7 @@ chrome.webRequest.onBeforeRequest.addListener(function(o){
 		var x=new XMLHttpRequest();
 		x.open('GET',o.url,false);
 		x.send();
-		if((!x.status||x.status==200)&&x.responseText[0]=='/') {
+		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)});

+ 10 - 0
common.js

@@ -13,4 +13,14 @@ function initI18n(callback){
 		if(callback) callback();
 	},true);
 }
+function getLocaleString(dict,key){
+	var lang=navigator.languages,i,lkey;
+	for(i=0;i<lang.length;i++) {
+		lkey=key+':'+lang[i];
+		if(lkey in dict) {
+			key=lkey;break;
+		}
+	}
+	return dict[key]||'';
+}
 var _=chrome.i18n.getMessage,$=document.querySelector.bind(document);

+ 1 - 1
manifest.json

@@ -1,6 +1,6 @@
 {
 	"name": "Violent monkey",
-	"version" : "2.1.6.7",
+	"version" : "2.1.6.8",
 	"manifest_version" : 2,
 	"description" : "__MSG_extDescription__",
 	"developer": {"name" : "Gerald", "url" : "http://geraldl.net"},

+ 3 - 3
options.js

@@ -31,7 +31,7 @@ function modifyItem(r){
 	var a=d.querySelector('.update');
 	if(a) a.disabled=r.updating;
 	a=d.querySelector('.name');
-	getName(a,n.custom.name||n.meta.name);
+	getName(a,n.custom.name||getLocaleString(n.meta,'name'));
 	if(o=n.custom.homepageURL||n.meta.homepageURL||n.meta.homepage) a.href=o;	// compatible with @homepage
 	if(o=n.meta.supportURL) {
 		a=d.querySelector('.support');a.classList.remove('hide');
@@ -39,7 +39,7 @@ function modifyItem(r){
 	}
 	getAuthor(d.querySelector('.author'),n.meta.author||'');
 	a=d.querySelector('.descrip');
-	getName(a,n.meta.description||'','&nbsp;');
+	getName(a,getLocaleString(n.meta,'description'),'&nbsp;');
 	setIcon(n,d.querySelector('.icon'));
 	a=d.querySelector('.enable');
 	a.innerHTML=n.enabled?_('buttonDisable'):_('buttonEnable');
@@ -222,7 +222,7 @@ function xLoad() {
 	ids.forEach(function(i){
 		var d=document.createElement('div'),n=map[i].obj;
 		d.className='ellipsis selected';
-		getName(d,n.custom.name||n.meta.name);
+		getName(d,n.custom.name||getLocaleString(n.meta,'name'));
 		xL.appendChild(d);
 	});
 }

+ 2 - 1
popup.js

@@ -31,7 +31,8 @@ function menuCommand(e) {
 function menuScript(s) {
 	if(s&&!scripts[s.id]) {
 		scripts[s.id]=s;
-		var n=s.meta.name?s.meta.name.replace(/&/g,'&amp;').replace(/</g,'&lt;'):'<em>'+_('labelNoName')+'</em>';
+		var n=s.custom.name||getLocaleString(s.meta,'name');
+		n=n?n.replace(/&/g,'&amp;').replace(/</g,'&lt;'):'<em>'+_('labelNoName')+'</em>';
 		loadItem(addItem(n,{
 			holder: pB,
 			symbol: '✓',