From 8ab83d8f8e9286ab1e3c1bf324f940dcc2a45a51 Mon Sep 17 00:00:00 2001 From: Cat73 <1901803382@qq.com> Date: Mon, 30 Nov 2015 13:42:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B8=E9=83=A8=E5=88=86=20onxxx=20?= =?UTF-8?q?=E7=9A=84=20event=20=E8=BF=90=E8=A1=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- remove_web_limits.user.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/remove_web_limits.user.js b/remove_web_limits.user.js index 893e2ea..cd96384 100644 --- a/remove_web_limits.user.js +++ b/remove_web_limits.user.js @@ -20,10 +20,10 @@ // @updateURL https://cat7373.github.io/remove-web-limits/remove_web_limits.user.js // @author Cat73 -// @version 1.2.2 +// @version 1.2.3 // @license LGPLv3 -// @compatible chrome Chrome_46.0.2490.86 + TamperMonkey + 脚本_1.2.2 测试通过 +// @compatible chrome Chrome_46.0.2490.86 + TamperMonkey + 脚本_1.2.3 测试通过 // @compatible firefox Firefox_42.0 + GreaseMonkey + 脚本_1.2.1 测试通过 // @compatible opera Opera_33.0.1990.115 + TamperMonkey + 脚本_1.1.3 测试通过 // @compatible safari 未测试 @@ -38,7 +38,6 @@ var hook_eventNames = "contextmenu|select|selectstart|copy|cut|dragstart".split("|"); var unhook_eventNames = "mousedown|mouseup|keydown|keyup".split("|"); var eventNames = hook_eventNames.concat(unhook_eventNames); -var eventNames_on = []; // 储存名称 var storageName = getRandStr('qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM', parseInt(Math.random() * 12 + 8)); // 储存被 Hook 的函数 @@ -70,8 +69,16 @@ function clearLoop() { var elements = getElements(); for(var i in elements) { - for(var j in eventNames_on) { - elements[i][eventNames_on[j]] = null; + for(var j in eventNames) { + var name = 'on' + eventNames[j]; + if(elements[i][name] != null && elements[i][name] != onxxx) { + if(unhook_eventNames.indexOf(eventNames[j]) >= 0) { + elements[i][storageName + name] = elements[i][name]; + elements[i][name] = onxxx; + } else { + elements[i][name] = null; + } + } } } } @@ -95,6 +102,13 @@ function unhook(e, self, funcsName) { e.returnValue = true; return true; } +function onxxx(e) { + var name = storageName + 'on' + e.type; + this[name](e); + + e.returnValue = true; + return true; +} // 获取随机字符串 function getRandStr(chs, len) { @@ -124,11 +138,6 @@ function addStyle(css) { // 初始化 function init() { - // 处理 onxxx 的 event 名称 - for(var i in eventNames) { - eventNames_on[i] = 'on' + eventNames[i]; - } - // 调用清理循环 setInterval(clearLoop, 30 * 1000); setTimeout(clearLoop, 2500);