-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathremoveWebLimit.js
More file actions
279 lines (242 loc) · 8.99 KB
/
removeWebLimit.js
File metadata and controls
279 lines (242 loc) · 8.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
export default {
icon: '<i class="fa-solid fa-gun fa-lg"></i>',
name: {
en: "Remove web limits",
vi: "Remove web limits",
},
description: {
en: `Pass to kill most of the site, you can lift the restrictions prohibited to copy, cut, select the text, right-click menu.
<br/><br/>
<h2 style="color:blue">WARNING</h2>
May cause some websites's functions to be disabled.<br/>
Only turn on when necessary (copy, right-click).<br/>
Turn off after using.`,
vi: `Mở khoá web, cho phép chọn text, copy, chuột phải trên mọi trang web
<br/><br/>
<h2 style="color:blue">Chú Ý</h2>
Có thể ảnh hưởng tới chức năng của 1 vài trang web.<br/>
Chỉ mở khi cần sử dụng (copy, chuột phải).<br/>
Tắt ngay khi sử dụng xong.`,
img: "",
},
infoLink: "https://greasyfork.org/scripts/14146",
onEnable: () => {
alert(`+Có thể ảnh hưởng tới chức năng của 1 vài trang web.
+ Chỉ mở khi cần sử dụng (copy, chuột phải).
+ Tắt ngay khi sử dụng xong.`);
},
onDocumentStart: () => {
// @description:zh 通杀大部分网站,可以解除禁止复制、剪切、选择文本、右键菜单的限制。
// @description:zh-CN 通杀大部分网站,可以解除禁止复制、剪切、选择文本、右键菜单的限制。
// @description:zh-TW 通殺大部分網站,可以解除禁止復制、剪切、選擇文本、右鍵菜單的限制。
// @description:ja サイトのほとんどを殺すために渡し、あなたは、コピー切り取り、テキスト、右クリックメニューを選択することは禁止の制限を解除することができます。
// @homepageURL https://cat7373.github.io/remove-web-limits/
// @supportURL https://github.com/Cat7373/remove-web-limits/issues/
// @author Cat73
// @version 1.3
// @license LGPLv3
// @compatible chrome Chrome_46.0.2490.86 + TamperMonkey + 脚本_1.3 测试通过
// @compatible firefox Firefox_42.0 + GreaseMonkey + 脚本_1.2.1 测试通过
// @compatible opera Opera_33.0.1990.115 + TamperMonkey + 脚本_1.1.3 测试通过
// @compatible safari 未测试
// @match *://*/*
// @grant none
// @run-at document-start
// ==/UserScript==
// prettier-ignore
(function() {
// 域名规则列表
var rules = {
black_rule: {
name: "black",
hook_eventNames: "",
unhook_eventNames: ""
},
default_rule: {
name: "default",
hook_eventNames: "contextmenu|select|selectstart|copy|cut|dragstart",
unhook_eventNames: "mousedown|mouseup|keydown|keyup",
dom0: true,
hook_addEventListener: true,
hook_preventDefault: true,
hook_set_returnValue: true,
add_css: true
}
};
// 域名列表
var lists = {
// 黑名单
black_list: [
/.*\.youtube\.com.*/,
/.*\.wikipedia\.org.*/,
/mail\.qq\.com.*/,
/translate\.google\..*/,
// added by hoangtran
/github\.dev.*/,
/hoangtran0410\.github\.io\/LOL2D/,
/regexr\.com/
]
};
// 要处理的 event 列表
var hook_eventNames, unhook_eventNames, eventNames;
// 储存名称
var storageName = getRandStr('qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM', parseInt(Math.random() * 12 + 8));
// 储存被 Hook 的函数
var EventTarget_addEventListener = EventTarget.prototype.addEventListener;
var document_addEventListener = document.addEventListener;
var Event_preventDefault = Event.prototype.preventDefault;
// Hook addEventListener proc
function addEventListener(type, func, useCapture) {
var _addEventListener = this === document ? document_addEventListener : EventTarget_addEventListener;
if(hook_eventNames.indexOf(type) >= 0) {
_addEventListener.apply(this, [type, returnTrue, useCapture]);
} else if(this && unhook_eventNames.indexOf(type) >= 0) {
var funcsName = storageName + type + (useCapture ? 't' : 'f');
if(this[funcsName] === undefined) {
this[funcsName] = [];
_addEventListener.apply(this, [type, useCapture ? unhook_t : unhook_f, useCapture]);
}
this[funcsName].push(func);
} else {
_addEventListener.apply(this, arguments);
}
}
// 清理循环
function clearLoop() {
var elements = getElements();
for(var i in elements) {
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;
}
}
}
}
}
// 返回true的函数
function returnTrue(e) {
return true;
}
function unhook_t(e) {
return unhook(e, this, storageName + e.type + 't');
}
function unhook_f(e) {
return unhook(e, this, storageName + e.type + 'f');
}
function unhook(e, self, funcsName) {
var list = self[funcsName];
for(var i in list) {
list[i](e);
}
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) {
var str = '';
while(len--) {
str += chs[parseInt(Math.random() * chs.length)];
}
return str;
}
// 获取所有元素 包括document
function getElements() {
var elements = Array.prototype.slice.call(document.getElementsByTagName('*'));
elements.push(document);
return elements;
}
// 添加css
function addStyle(css) {
const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = UfsGlobal.DOM.createTrustedHtml(css);
(document.head || document.documentElement).appendChild(style);
}
// 获取目标域名应该使用的规则
function getRule(url) {
function testUrl(list, url) {
for(var i in list) {
if(list[i].test(url)) {
return true;
}
}
return false;
}
if(testUrl(lists.black_list, url)) {
return rules.black_rule;
}
return rules.default_rule;
}
// 初始化
function init() {
// 获取当前域名的规则
var url = window.location.host + window.location.pathname;
var rule = getRule(url);
if(rule.name === rules.black_rule.name) {
return;
} else {
UfsGlobal.DOM.notify({
msg:"UsefulScript - Remove web limit - ON (" + rule.name + ")",
align: "center"
})
}
// 设置 event 列表
hook_eventNames = rule.hook_eventNames.split("|");
// TODO Allowed to return value
unhook_eventNames = rule.unhook_eventNames.split("|");
eventNames = hook_eventNames.concat(unhook_eventNames);
// 调用清理 DOM0 event 方法的循环
if(rule.dom0) {
setInterval(clearLoop, 30 * 1000);
setTimeout(clearLoop, 2500);
window.addEventListener('load', clearLoop, true);
clearLoop();
}
// hook addEventListener
if(rule.hook_addEventListener) {
EventTarget.prototype.addEventListener = addEventListener;
document.addEventListener = addEventListener;
}
// hook preventDefault
if(rule.hook_preventDefault) {
Event.prototype.preventDefault = function() {
if(eventNames.indexOf(this.type) < 0) {
Event_preventDefault.apply(this, arguments);
}
};
}
// Hook set returnValue
if(rule.hook_set_returnValue) {
Event.prototype.__defineSetter__('returnValue', function() {
if(this.returnValue !== true && eventNames.indexOf(this.type) >= 0) {
this.returnValue = true;
}
});
}
console.debug('url: ' + url, 'storageName:' + storageName, 'rule: ' + rule.name);
// 添加CSS
if(rule.add_css) {
addStyle(`html, * {
-webkit-user-select:text!important;
-moz-user-select:text!important;
user-select:text!important;
-ms-user-select:text!important;
-khtml-user-select:text!important;
}`);
}
}
init();
})();
},
};