Browse Source

Remove unuseful code

Gerald 10 years ago
parent
commit
9567ca444f
6 changed files with 9 additions and 212 deletions
  1. 1 1
      README.md
  2. 3 3
      package.json
  3. 2 2
      src/background/index.html
  4. 2 2
      src/background/main.js
  5. 0 203
      src/confirm.js
  6. 1 1
      src/manifest.json

+ 1 - 1
README.md

@@ -2,7 +2,7 @@ Violentmonkey
 =============
 
 Violentmonkey provides userscripts support for Chromium-based Opera.  
-Violentmonkey for Opera Presto: <https://github.com/gera2ld/Violentmonkey-oex>
+Violentmonkey for Opera Presto: <https://github.com/Violentmonkey/Violentmonkey-oex>
 
 Multiple language
 ---

+ 3 - 3
package.json

@@ -11,11 +11,11 @@
   "author": "Gerald <[email protected]>",
   "repository": {
     "type": "git",
-    "url": "https://github.com/gera2ld/Violentmonkey.git"
+    "url": "https://github.com/Violentmonkey/Violentmonkey.git"
   },
   "bugs": {
-    "url": "https://github.com/gera2ld/Violentmonkey/issues"
+    "url": "https://github.com/Violentmonkey/Violentmonkey/issues"
   },
-  "homepage": "https://github.com/gera2ld/Violentmonkey",
+  "homepage": "https://github.com/Violentmonkey/Violentmonkey",
   "license": "ISC"
 }

+ 2 - 2
src/background.html → src/background/index.html

@@ -5,7 +5,7 @@
 		<title>ViolentMonkey</title>
 	</head>
   <body>
-		<script src="common.js"></script>
-		<script src="background.js"></script>
+		<script src="/common.js"></script>
+		<script src="main.js"></script>
   </body>
 </html>

+ 2 - 2
src/background.js → src/background/main.js

@@ -21,7 +21,7 @@ function getUniqId() {
 function notify(options) {
 	chrome.notifications.create(options.id || 'ViolentMonkey', {
 		type: 'basic',
-		iconUrl: 'images/icon128.png',
+		iconUrl: '/images/icon128.png',
 		title: options.title + ' - ' + _.i18n('extName'),
 		message: options.body,
 		isClickable: options.isClickable,
@@ -936,7 +936,7 @@ function initMessages() {
 initDb(function() {
 	initPosition(initMessages);
 	chrome.browserAction.setIcon({
-		path: 'images/icon19' + (_.options.get('isApplied') ? '' : 'w') + '.png',
+		path: '/images/icon19' + (_.options.get('isApplied') ? '' : 'w') + '.png',
 	});
 	setTimeout(autoUpdate, 2e4);
 });

+ 0 - 203
src/confirm.js

@@ -1,203 +0,0 @@
-'use strict';
-!function() {
-	var delay = 2000;
-	var data = {};
-	var lbUrl = $('#url');
-	var lbMsg = $('#msg');
-	var cbClose = $('#cbClose');
-	var cbTrack = $('#cbTrack');
-	var btInstall = $('#bInstall');
-	var options = $('.confirm-options');
-	var timer, editor;
-
-	function showMessage(message, title) {
-		lbMsg.innerHTML = message;
-		lbMsg.setAttribute('title', title || message);
-	}
-
-	function zfill(num, length) {
-		num = num.toString();
-		while(num.length < length) num = '0' + num;
-		return num;
-	}
-
-	function getTimeString() {
-		var now = new Date();
-		return zfill(now.getHours(), 2) + ':' +
-			zfill(now.getMinutes(), 2) + ':' +
-			zfill(now.getSeconds(), 2);
-	}
-
-	function getScriptFile(cb) {
-		var x = new XMLHttpRequest();
-		x.open('GET', data.url, true);
-		x.onloadend = function() {
-			var x = this;
-			if(!x.status) data.local = true;
-			if(x.status && x.status != 200 || !x.responseText)
-				showMessage(_('msgErrorLoadingData'));
-			else
-				cb(x.responseText);
-		};
-		x.send();
-	}
-
-	function loadDependency(dict, urls, isBlob, cb) {
-		urls.forEach(function(url){
-			if(dict[url]) return cb();
-			var x = new XMLHttpRequest();
-			x.open('GET', url, true);
-			if(isBlob) x.responseType = 'blob';
-			x.onloadend = function(){
-				var x = this;
-				if(!x.status || x.status == 200) {
-					if(isBlob) {
-						var r = new FileReader();
-						r.onload = function(e) {
-							dict[url] = window.btoa(x.result);
-							cb();
-						};
-						r.readAsBinaryString(x.response);
-					} else {
-						dict[url] = x.responseText;
-						cb();
-					}
-				} else cb(url);
-			};
-			x.send();
-		});
-	}
-
-	function parseMeta(body, cb) {
-		function finish(){
-			showMessage(_('msgLoadedData'));
-			btInstall.disabled = false;
-			data.depStatus = 1;
-			if(cb) cb();
-		}
-		function finishOne(errUrl) {
-			if(errUrl) err.push(errUrl);
-			i ++;
-			if(i >= length) {
-				if(err.length) {
-					showMessage(_('msgErrorLoadingDependency'), err.join('\n'));
-				} else finish();
-			} else showMessage(_('msgLoadingDependency', [i, length]));
-		}
-		var urls = [];
-		var err = [];
-		var i;
-		var length;
-		data.depStatus=0;
-		chrome.runtime.sendMessage({cmd: 'ParseMeta', data: body}, function(script) {
-			for(i in script.resources) urls.push(script.resources[i]);
-			length = script.require.length + urls.length;
-			if(length) {
-				showMessage(_('msgLoadingDependency', [i = 0, length]));
-				loadDependency(data.require = {}, script.require, false, finishOne);
-				loadDependency(data.resources = {}, urls, true, finishOne);
-			} else finish();
-		});
-	}
-
-	function updateClose(){
-		if(cbTrack.disabled = cbClose.checked) {
-			cbTrack.checked = false;
-			updateLocal();
-		}
-		setOption('closeAfterInstall', cbClose.checked);
-	}
-
-	function updateLocal(){
-		setOption('trackLocalFile', cbTrack.checked);
-		if(cbTrack.checked && data.depStatus && data.local)
-			btInstall.disabled=false;
-	}
-
-	function trackLocalFile(){
-		function check(){
-			timer=null;
-			getScriptFile(function(body) {
-				var oldbody = editor.getValue();
-				editor.setValue(body);
-				body = editor.getValue();
-				if(oldbody != body)
-					parseMeta(body, function(){
-						if(cbTrack.checked) install();
-					});
-				else if(cbTrack.checked)
-					timer = setTimeout(check, delay);
-			});
-		}
-		if(!timer) timer = setTimeout(check, delay);
-	}
-
-	function install(){
-		btInstall.disabled=true;
-		chrome.runtime.sendMessage({
-			cmd:'ParseScript',
-			data:{
-				url: data.url,
-				from: data.from,
-				code: editor.getValue(),
-				require: data.require,
-				resources: data.resources,
-			},
-		}, function(res){
-			showMessage(res.message + '[' + getTimeString() + ']');
-			if(res.code >= 0) {
-				if(cbClose.checked) close();
-				else if(data.local && cbTrack.checked) trackLocalFile();
-			}
-		});
-	}
-
-	function close() {
-		window.close();
-	}
-
-	function bindEvents() {
-		cbClose.checked = getOption('closeAfterInstall');
-		updateClose();
-		cbClose.addEventListener('change', updateClose, false);
-		cbTrack.checked = getOption('trackLocalFile');
-		cbTrack.addEventListener('change', updateLocal, false);
-		$('#bClose').addEventListener('click', close, false);
-		btInstall.addEventListener('click', install, false);
-		var hideOptions = function(){
-			options.style.display = '';
-			document.removeEventListener('mousedown', hideOptions, false);
-		};
-		$('#bOptions').addEventListener('click', function(e){
-			options.style.right = this.parentNode.offsetWidth - this.offsetWidth - this.offsetLeft + 'px';
-			options.style.display = 'block';
-			document.addEventListener('mousedown', hideOptions, false);
-		}, false);
-		options.addEventListener('mousedown', stopPropagation, false);
-	}
-
-	initEditor({
-		container: $('.editor-code'),
-		callback: function(_editor) {
-			editor = _editor;
-			location.search.slice(1).split('&').forEach(function(part) {
-				part.replace(/^([^=]*)=(.*)$/, function(value, group1, group2) {
-					data[group1] = decodeURIComponent(group2);
-				});
-			});
-			lbUrl.innerHTML = _('msgScriptURL', [data.url || '-']);
-			if(data.url) {
-				lbUrl.setAttribute('title', data.url);
-				showMessage(_('msgLoadingData'));
-				getScriptFile(function(body) {
-					editor.setValueAndFocus(body);
-					parseMeta(body);
-				});
-			}
-		},
-		onexit: close,
-		readonly: true,
-	});
-	bindEvents();
-	initI18n();
-}();

+ 1 - 1
src/manifest.json

@@ -20,7 +20,7 @@
     "default_popup": "popup.html"
   },
   "background": {
-    "page": "background.html"
+    "page": "background/index.html"
   },
   "options_page": "options/index.html",
   "content_scripts": [