Skip to content

Commit

Permalink
整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Cat7373 committed Nov 24, 2015
1 parent b81cbdb commit 6cafd48
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions remove_web_limits.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// @run-at document-start
// ==/UserScript==


// 要处理的event
var eventNames = "contextmenu|select|selectstart|copy|cut|dragstart|mousedown".split("|");
// 原始 addEventListener 的保存位置
Expand All @@ -40,17 +41,18 @@ function addEventListener(event, func, useCapture) {
if(eventNames.indexOf(event) >= 0) {
func = returnTrue;
}

this[addEventListenerName](event, func, useCapture);
}

// 清理循环
function clearLoop() {
var elements = getElements();

for(var i = 0; i < elements.length; i++) {
for(var i in elements) {
var element = elements[i];

for(var j = 0; j < eventNames.length; j++) {
for(var j in eventNames) {
element['on' + eventNames[j]] = null;
}
}
Expand All @@ -64,20 +66,24 @@ function returnTrue() {
// 获取随机字符串
function getRandStr(chs, len) {
var str = '';

for(var i = 0; i < len; i++) {
str += chs[parseInt(Math.random() * chs.length)];
}
return str;

return str;
}

// 获取所有元素 包括document
function getElements() {
var elements = document.getElementsByTagName('*');

var elements2 = [];
for(var i = 0; i < elements.length; i++) {
elements2[i] = elements[i];
elements2.push(elements[i]);
}
elements2[elements2.length] = document;
elements2.push(document);

return elements2;
}

Expand All @@ -96,10 +102,10 @@ function init() {
clearLoop();

// 添加CSS
GM_addStyle("html, * {-webkit-user-select:text!important; -moz-user-select:text!important;}");
GM_addStyle('html, * {-webkit-user-select:text!important; -moz-user-select:text!important;}');

// 输出原始 addEventListener 位置
GM_log("原始 addEventListener 名称:" + addEventListenerName);
GM_log('原始 addEventListener 名称:' + addEventListenerName);
}

init();

0 comments on commit 6cafd48

Please sign in to comment.