Quellcode durchsuchen

added option for closing confirm window after script installation

Gerald vor 12 Jahren
Ursprung
Commit
d4fd94314b

+ 5 - 1
_locales/cs/messages.json

@@ -55,6 +55,10 @@
 		"message": "Instaluji skript", 
 		"description": "Shown in the title of the confirm page while trying to install a script."
 	}, 
+	"optionClose": {
+		"message": "Close after installation", 
+		"description": "Option to close confirm window after installation."
+	}, 
 	"buttonConfirmInstallation": {
 		"message": "Potvrdit instalaci", 
 		"description": "Button to confirm installation of a script."
@@ -331,4 +335,4 @@
 		"message": "Skriptové příkazy...", 
 		"description": "Menu item to list script commands."
 	}
-}
+}

+ 4 - 0
_locales/en/messages.json

@@ -55,6 +55,10 @@
 		"message": "Installing script", 
 		"description": "Shown in the title of the confirm page while trying to install a script."
 	}, 
+	"optionClose": {
+		"message": "Close after installation", 
+		"description": "Option to close confirm window after installation."
+	}, 
 	"buttonConfirmInstallation": {
 		"message": "Confirm installation", 
 		"description": "Button to confirm installation of a script."

+ 4 - 0
_locales/pl/messages.json

@@ -55,6 +55,10 @@
 		"message": "Instalowanie skryptu", 
 		"description": "Shown in the title of the confirm page while trying to install a script."
 	}, 
+	"optionClose": {
+		"message": "Close after installation", 
+		"description": "Option to close confirm window after installation."
+	}, 
 	"buttonConfirmInstallation": {
 		"message": "Potwierdź instalację", 
 		"description": "Button to confirm installation of a script."

+ 4 - 0
_locales/ru/messages.json

@@ -55,6 +55,10 @@
 		"message": "Installing script", 
 		"description": "Shown in the title of the confirm page while trying to install a script."
 	}, 
+	"optionClose": {
+		"message": "Close after installation", 
+		"description": "Option to close confirm window after installation."
+	}, 
 	"buttonConfirmInstallation": {
 		"message": "Confirm installation", 
 		"description": "Button to confirm installation of a script."

+ 5 - 1
_locales/zh/messages.json

@@ -55,6 +55,10 @@
 		"message": "安装脚本", 
 		"description": "Shown in the title of the confirm page while trying to install a script."
 	}, 
+	"optionClose": {
+		"message": "安装完成后关闭", 
+		"description": "Option to close confirm window after installation."
+	}, 
 	"buttonConfirmInstallation": {
 		"message": "确认安装", 
 		"description": "Button to confirm installation of a script."
@@ -331,4 +335,4 @@
 		"message": "脚本命令...", 
 		"description": "Menu item to list script commands."
 	}
-}
+}

+ 3 - 1
background.js

@@ -15,6 +15,7 @@ function initDb(callback) {
 			{key:'showButton',value:true},
 			{key:'isApplied',value:true},
 			{key:'autoUpdate',value:true},
+			{key:'closeAfterInstall',value:false},
 			{key:'search',value:_('defaultSearch')},
 		].forEach(function(i){o.add(i);});
 		// scripts: id uri custom meta enabled update code position
@@ -384,7 +385,8 @@ function getOption(data,src,callback){
 	var o=db.transaction('settings').objectStore('settings');
 	o.get(data).onsuccess=function(e){
 		var r=e.target.result;
-		if(callback) callback(r.value);
+		if(r) r=r.value;
+		if(callback) callback(r);
 	};
 }
 function setOption(data,src,callback){

+ 7 - 10
confirm.html

@@ -3,25 +3,22 @@
 	<head>
 		<meta http-equiv="content-type" content="text/html;charset=utf-8">
 		<link rel="stylesheet" type="text/css" href="style.css" />
-		<link rel="stylesheet" type="text/css" href="lib/codemirror/codemirror.css" />
 		<link rel="shortcut icon" type="image/png" href="icons/icon_16.png" />
-		<script type="text/javascript" src="lib/codemirror/codemirror.js"></script>
-		<script type="text/javascript" src="lib/codemirror/javascript.js"></script>
-		<script type="text/javascript" src="lib/codemirror/continuecomment.js"></script>
-		<script type="text/javascript" src="lib/codemirror/matchbrackets.js"></script>
-		<script type="text/javascript" src="lib/codemirror/match-highlighter.js"></script>
-		<script type="text/javascript" src="lib/codemirror/search.js"></script>
-		<script type="text/javascript" src="lib/codemirror/searchcursor.js"></script>
+		<script type="text/javascript" src="lib/src-min-noconflict/ace.js"></script>
 		<title class=i18n>extName</title>
 	</head>
 	<body class=fill>
 		<table class=frame>
 			<tr>
 				<td><h2><span class=i18n>labelInstall</span> - <span class=i18n>extName</span></h2></td>
-				<td class=buttons><button class=i18n id=bInstall disabled=disabled>buttonConfirmInstallation</button> <button class=i18n id=bClose>buttonClose</button></td>
+				<td class=buttons>
+					<input type=checkbox id=cClose><label for=cClose class=i18n>optionClose</label>
+					<button class=i18n id=bInstall disabled=disabled>buttonConfirmInstallation</button>
+					<button class=i18n id=bClose>buttonClose</button>
+				</td>
 			</tr>
 			<tr><td colspan=2 id=msg></td></tr>
-			<tr class=expand><td colspan=2 class=expandr><textarea id=eCode class=expanda></textarea></td></tr>
+			<tr class=expand><td id=eCode colspan=2 class=expandr></td></tr>
 			<tr><td colspan=2 class=center><span class=i18n>anchorSupportPage</span> - <span class=i18n>anchorAuthor</span> - 2013</td></tr>
 		</table>
 	</body>

+ 17 - 12
confirm.js

@@ -6,22 +6,24 @@ function checkScript(t){
 		});
 	} else {	// may be JS code
 		M.innerHTML=_('msgLoadedJS',[data.url]);
-		T.setValue(t);
+		T.setValue(t);T.gotoLine(0,0);
 		I.disabled=false;
 	}
 }
 var $=document.getElementById.bind(document),M=$('msg'),I=$('bInstall'),data={},
-		T=CodeMirror.fromTextArea($('eCode'),{
-			lineNumbers:true,
-			matchBrackets:true,
-			mode:'text/typescript',
-			lineWrapping:true,
-			indentUnit:4,
-			indentWithTabs:true,
-			readOnly:true,
-		});
+		C=$('cClose'),T=ace.edit('eCode');
+T.setTheme('ace/theme/github');
+T.setReadOnly(true);
+(function(s){
+	s.setMode('ace/mode/javascript');
+	s.setUseWrapMode(true);
+	s.setUseWorker(true);
+})(T.getSession());
 initCSS();initI18n();
 $('bClose').onclick=function(){window.close();};
+C.onchange=function(){
+	chrome.runtime.sendMessage({cmd:'SetOption',data:{key:'closeAfterInstall',value:C.checked}});
+};
 I.onclick=function(){
 	chrome.runtime.sendMessage({
 		cmd:'ParseScript',
@@ -38,12 +40,15 @@ chrome.runtime.onMessage.addListener(function(req,src,callback) {
 		ShowMessage: function(o){
 			M.innerHTML=o.message;
 			if(callback) callback();
+			if(o.status>=0&&C.checked) window.close();
 		},
 	},f=maps[req.cmd];
 	if(f) f(req.data,src,callback);
 	return true;
 });
-(function(s){
+chrome.runtime.sendMessage({cmd:'GetOption',data:'closeAfterInstall'},function(o){
+	C.checked=!!o;
+	var s=location.search.slice(1);
 	s.split('&').forEach(function(i){
 		i.replace(/^([^=]*)=(.*)$/,function(r,g1,g2){data[g1]=decodeURIComponent(g2);});
 	});
@@ -58,4 +63,4 @@ chrome.runtime.onMessage.addListener(function(req,src,callback) {
 		};
 		x.send();
 	}
-})(location.search.slice(1));
+});

+ 1 - 1
options.html

@@ -48,7 +48,7 @@
 			<tr class=expand><td id=eCode colspan=2 class=expandr></td></tr>
 			<tr>
 				<td colspan=2>
-					<label class=left><input type=checkbox id=eUpdate><span class=i18n>labelAllowUpdate</span></label>
+					<label><input type=checkbox id=eUpdate><span class=i18n>labelAllowUpdate</span></label>
 					<div class=right>
 						<button id=eSave class=i18n>buttonSave</button>
 						<button id=eSaveClose class=i18n>buttonSaveClose</button>

+ 1 - 1
options.js

@@ -30,7 +30,7 @@ function loadItem(o,r){
 	+'<span class=message></span>'
 	+'<div class=panelB>'
 		+'<button data=edit>'+_('buttonEdit')+'</button> '
-		+'<button data=enable>'+_(n.enabled?'buttonDisable':'buttonEnable')+'</button> '
+		+'<button data=enable>'+(n.enabled?_('buttonDisable'):_('buttonEnable'))+'</button> '
 		+'<button data=remove>'+_('buttonRemove')+'</button>'
 	+'</div>';
 	d.className=n.enabled?'':'disabled';