瀏覽代碼

added notifications when `@grant` is not found in a script

Signed-off-by: Gerald <[email protected]>
Gerald 11 年之前
父節點
當前提交
d0ef9935c5
共有 7 個文件被更改,包括 83 次插入22 次删除
  1. 12 4
      _locales/cs/messages.json
  2. 12 4
      _locales/en/messages.json
  3. 12 4
      _locales/pl/messages.json
  4. 12 4
      _locales/ru/messages.json
  5. 12 4
      _locales/zh/messages.json
  6. 21 0
      background.js
  7. 2 2
      manifest.json

+ 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

+ 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';"
 }