Ver código fonte

Merge pull request #17 from gera2ld/dev

Dev
Gerald 11 anos atrás
pai
commit
bc4020b10e

+ 12 - 4
_locales/cs/messages.json

@@ -23,6 +23,18 @@
 		"description": "Message shown when a script is installed.",
 		"message": "Skript nainstalován."
 	},
+	"Warning": {
+		"description": "Show warnings with a notification.",
+		"message": "Warning"
+	},
+	"msgWarnGrant": {
+		"description": "Message shown when `@grant` is not found in a script.",
+		"message": "Script [$1] has no `@grant` lines! Click to see more details."
+	},
+	"labelNoName": {
+		"description": "Text as the name of a script when no @name is assigned.",
+		"message": "Jméno nebylo definováno"
+	},
 	"msgUpdating": {
 		"description": "Message shown when a new version of script is being fetched.",
 		"message": "Aktualizuji..."
@@ -267,10 +279,6 @@
 		"description": "Button to save modifications of a script and then close the editing page.",
 		"message": "Uložit a Zavřít"
 	},
-	"labelNoName": {
-		"description": "Text as the name of a script when no @name is assigned.",
-		"message": "Jméno nebylo definováno"
-	},
 	"hintSupportPage": {
 		"description": "Hint for support page.",
 		"message": "Support page"

+ 12 - 4
_locales/en/messages.json

@@ -23,6 +23,18 @@
 		"description": "Message shown when a script is installed.",
 		"message": "Script installed."
 	},
+	"Warning": {
+		"description": "Show warnings with a notification.",
+		"message": "Warning"
+	},
+	"msgWarnGrant": {
+		"description": "Message shown when `@grant` is not found in a script.",
+		"message": "Script [$1] has no `@grant` lines! Click to see more details."
+	},
+	"labelNoName": {
+		"description": "Text as the name of a script when no @name is assigned.",
+		"message": "No Name"
+	},
 	"msgUpdating": {
 		"description": "Message shown when a new version of script is being fetched.",
 		"message": "Updating..."
@@ -267,10 +279,6 @@
 		"description": "Button to save modifications of a script and then close the editing page.",
 		"message": "Save & Close"
 	},
-	"labelNoName": {
-		"description": "Text as the name of a script when no @name is assigned.",
-		"message": "No Name"
-	},
 	"hintSupportPage": {
 		"description": "Hint for support page.",
 		"message": "Support page"

+ 12 - 4
_locales/pl/messages.json

@@ -23,6 +23,18 @@
 		"description": "Message shown when a script is installed.",
 		"message": "Skrypt zainstalowany"
 	},
+	"Warning": {
+		"description": "Show warnings with a notification.",
+		"message": "Warning"
+	},
+	"msgWarnGrant": {
+		"description": "Message shown when `@grant` is not found in a script.",
+		"message": "Script [$1] has no `@grant` lines! Click to see more details."
+	},
+	"labelNoName": {
+		"description": "Text as the name of a script when no @name is assigned.",
+		"message": "Bez nazwy"
+	},
 	"msgUpdating": {
 		"description": "Message shown when a new version of script is being fetched.",
 		"message": "Aktualizowanie skryptu..."
@@ -267,10 +279,6 @@
 		"description": "Button to save modifications of a script and then close the editing page.",
 		"message": "Zapisz skrypt i zamknij edytor"
 	},
-	"labelNoName": {
-		"description": "Text as the name of a script when no @name is assigned.",
-		"message": "Bez nazwy"
-	},
 	"hintSupportPage": {
 		"description": "Hint for support page.",
 		"message": "Strona wsparcia"

+ 12 - 4
_locales/ru/messages.json

@@ -23,6 +23,18 @@
 		"description": "Message shown when a script is installed.",
 		"message": "Скрипт установлен."
 	},
+	"Warning": {
+		"description": "Show warnings with a notification.",
+		"message": "Warning"
+	},
+	"msgWarnGrant": {
+		"description": "Message shown when `@grant` is not found in a script.",
+		"message": "Script [$1] has no `@grant` lines! Click to see more details."
+	},
+	"labelNoName": {
+		"description": "Text as the name of a script when no @name is assigned.",
+		"message": "Новый скрипт"
+	},
 	"msgUpdating": {
 		"description": "Message shown when a new version of script is being fetched.",
 		"message": "Обновление..."
@@ -267,10 +279,6 @@
 		"description": "Button to save modifications of a script and then close the editing page.",
 		"message": "Сохранить и закрыть"
 	},
-	"labelNoName": {
-		"description": "Text as the name of a script when no @name is assigned.",
-		"message": "Новый скрипт"
-	},
 	"hintSupportPage": {
 		"description": "Hint for support page.",
 		"message": "Support page"

+ 12 - 4
_locales/zh/messages.json

@@ -23,6 +23,18 @@
 		"description": "Message shown when a script is installed.",
 		"message": "脚本已安装。"
 	},
+	"Warning": {
+		"description": "Show warnings with a notification.",
+		"message": "警告"
+	},
+	"msgWarnGrant": {
+		"description": "Message shown when `@grant` is not found in a script.",
+		"message": "脚本【$1】没有`@grant`行!点击查看更多信息。"
+	},
+	"labelNoName": {
+		"description": "Text as the name of a script when no @name is assigned.",
+		"message": "名字为空"
+	},
 	"msgUpdating": {
 		"description": "Message shown when a new version of script is being fetched.",
 		"message": "正在更新..."
@@ -267,10 +279,6 @@
 		"description": "Button to save modifications of a script and then close the editing page.",
 		"message": "保存并关闭"
 	},
-	"labelNoName": {
-		"description": "Text as the name of a script when no @name is assigned.",
-		"message": "名字为空"
-	},
 	"hintSupportPage": {
 		"description": "Hint for support page.",
 		"message": "支持页面"

+ 21 - 0
background.js

@@ -1,4 +1,17 @@
 var db,port=null,pos=0;
+function notify(title,options) {
+	function show() {
+		var n=new Notification(title+' - '+_('extName'),{
+			body:options.body,
+			icon:'images/icon128.png',
+		});
+		n.onclick=options.onclick;
+	}
+	show();
+	/*Notification.requestPermission(function(e){
+		if(e=='granted') show(); else console.log('Notification: '+options.body);
+	});*/
+}
 function initDb(callback) {
 	var request=indexedDB.open('Violentmonkey',1);
 	request.onsuccess=function(e){db=request.result;if(callback) callback();};
@@ -359,6 +372,14 @@ function parseScript(o,src,callback) {
 			if(o.url&&!/^(file|data):/.test(o.url)) c.custom.lastInstallURL=o.url;
 			saveScript(c,src).onsuccess=function(e){
 				r.id=c.id=e.target.result;r.obj=getMeta(c);finish();
+				if(!meta.grant.length)
+					notify(_('Warning'),{
+						body:_('msgWarnGrant',[meta.name||_('labelNoName')]),
+						onclick:function(){
+							chrome.tabs.create({url:'http://wiki.greasespot.net/@grant'});
+							this.close();
+						},
+					});
 			};
 		});
 		meta.require.forEach(function(u){	// @require

+ 44 - 8
injected.js

@@ -145,7 +145,7 @@ var comm={
 		}
 		function wrapper(){
 			// functions and properties
-			function wrapFunction(o,i,c){
+			/*function wrapFunction(o,i,c){
 				var f=function(){
 					var r;
 					try{r=Function.apply.apply(o[i],[o,arguments]);}
@@ -155,9 +155,46 @@ var comm={
 				f.__proto__=o[i];f.prototype=o[i].prototype;
 				return f;
 			}
-			function wrapWindow(w){return w==window?t:w;}
-			function wrapItem(i){
-				try{	// avoid reading protected data
+			function wrapWindow(w){return w==window?t:w;}*/
+			function wrapItem(i,wrap){
+				var type=null,value;
+				function initProperty() {
+					if(!type) {
+						value=window[i];
+						type=typeof value;
+						if(type=='function'&&wrap) {
+							var o=value;
+							value=function(){
+								var r;
+								try {
+									r=Function.apply.apply(o,[window,arguments]);
+								} catch(e) {
+									console.log('Error calling '+i+':\n'+e.stack);
+								}
+								return r===window?t:r;
+							};
+							value.__proto__=o;
+							value.prototype=o.prototype;
+						}
+					}
+				}
+				try {
+					Object.defineProperty(t,i,{
+						get:function(){
+							initProperty();
+							return value===window?t:value;
+						},
+						set:function(v){
+							initProperty();
+							value=v;
+							if(type!='function') window[i]=v;
+							type='custom';
+						},
+					});
+				} catch(e) {
+					// ignore protected data
+				}
+				/*try{	// avoid reading protected data
 					if(typeof window[i]=='function') {
 						if(itemWrapper) t[i]=itemWrapper(window,i,wrapWindow);
 						else t[i]=window[i];
@@ -165,12 +202,11 @@ var comm={
 						get:function(){return wrapWindow(window[i]);},
 						set:function(v){window[i]=v;},
 					});
-				}catch(e){}
+				}catch(e){}*/
 			}
-			var t=this,itemWrapper=null;
+			var t=this/*,itemWrapper=null*/;
 			comm.prop1.forEach(wrapItem);
-			itemWrapper=wrapFunction;
-			comm.prop2.forEach(wrapItem);
+			comm.prop2.forEach(function(i){wrapItem(i,true);});
 		}
 		function wrapGM(c){
 			// Add GM functions

+ 2 - 2
manifest.json

@@ -1,6 +1,6 @@
 {
 	"name": "Violent monkey",
-	"version" : "2.1.6.5",
+	"version" : "2.1.6.6",
 	"manifest_version" : 2,
 	"description" : "__MSG_extDescription__",
 	"developer": {"name" : "Gerald", "url" : "http://geraldl.net"},
@@ -27,6 +27,6 @@
 		"all_frames" : true
 	}],
 	"web_accessible_resources" : [],
-	"permissions" : ["tabs", "<all_urls>", "webRequest", "webRequestBlocking"],
+	"permissions" : ["tabs", "<all_urls>", "webRequest", "webRequestBlocking", "notifications"],
 	"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'unsafe-eval';"
 }

+ 0 - 3
options.js

@@ -321,13 +321,10 @@ function mReset(){
 	}
 	cI.checked=c._include!=false;
 	mI.value=(c.include||e).join('\n');
-	mI.placeholder=m.include.join('\n');
 	cM.checked=c._match!=false;
 	mM.value=(c.match||e).join('\n');
-	mM.placeholder=m.match.join('\n');
 	cE.checked=c._exclude!=false;
 	mE.value=(c.exclude||e).join('\n');
-	mE.placeholder=m.exclude.join('\n');
 }
 function gotScript(o){
 	E.classList.remove('hide');