-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanti-disabler2.user.js
224 lines (190 loc) · 7.33 KB
/
anti-disabler2.user.js
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
// ==UserScript==
// @name Anti-Disabler 2
// @namespace https://github.com/zephyrer/
// @description Restore copy, selection and context menus on sites that try to disable them, reissued from "Anti-Disabler" of JoeSimmons & Mark Pilgrim.
// @include http://*
// @include https://*
// @exclude http://*.google.com/*
// @exclude https://*.google.com/*
// @exclude http://*.youtube.com/*
// @exclude http://youtube.com/*
// @exclude https://*.youtube.com/*
// @exclude https://youtube.com/*
// @exclude http://*.facebook.com/*
// @exclude https://*.facebook.com/*
// @exclude http://userscripts.org/*
// @exclude https://userscripts.org/*
// @exclude http://userscripts-mirror.org/*
// @exclude https://greasyfork.org/*
// @exclude https://openuserjs.org/*
// @exclude http://*.deviantart.com/*
// @exclude http://www.jslint.com/*
// @exclude https://www.jslint.com/*
// @exclude file:///*/perf.html*
// @exclude http://ninjakiwi.com/*
// @exclude https://ninjakiwi.com/*
// @exclude http://jsfiddle.net/*
// @exclude https://jsfiddle.net/*
// @exclude http://*.wikipedia.org/*
// @exclude https://*.wikipedia.org/*
// @downloadURL https://github.com/zephyrer/userscripts/raw/master/anti-disabler2.user.js
// @updateURL https://github.com/zephyrer/userscripts/raw/master/anti-disabler2.meta.js
// @require https://raw.githubusercontent.com/joesimmons/jsl/master/versions/jsl-1.3.1.js
// @copyright Efisio Zephyr
// @version 0.2.2.2
// @grant none
// @run-at document-start
// ==/UserScript==
/* CHANGELOG
0.2.2 (5/27/2016)
- update namespace
0.2.0 (5/27/2016)
- refactor main process out into an independent function
- run main process again at JSL status "complete" to adapt to some situations that adding listeners later
0.1.1 (5/26/2016)
- add process for another jquery existence (window.jQuery)
- add jquery .off() to removes event handlers that were attached with .on().
0.1.0 (5/26/2016)
- reproduction
- update required JSL script to 1.3.1
- update exclusions
1.1.3 (3/20/2014)
- fixed a variable reference error
- made the event blacklist regex case-insensitive
1.1.2 (3/19/2014)
- changed include to http and https protocols only
*/
(function () {
'use strict';
// Anti-Disabler modified by Joe Simmons
/*
Other mild credit:
absurdlyobfuscated
Jeroenz0r
rinopo_d
*/
var handlers_blacklist = [
'oncontextmenu',
'onbeforecopy',
'oncopy',
'oncut',
'ondrag',
'ondragend',
'ondragenter',
'ondragleave',
'ondragover',
'ondragstart',
'ondrop',
'onmousedown',
'onmouseup',
//'onmouseover',
//'onmouseout',
//'onmouseenter',
//'onmouseleave',
'onselect',
'onselectstart'
],
//rEventBlacklist = new RegExp( handlers_blacklist.join('|').replace(/^on/g, ''), 'i' ),
rEventBlacklist = new RegExp( handlers_blacklist.join('|').replace(/^on/, '').replace(/\|on/g, '|'), 'ig' ),
oldAEL, win;
// unwraps the element so we can use its methods freely
function unwrap(elem) {
if (elem) {
if (typeof XPCNativeWrapper === 'function' && typeof XPCNativeWrapper.unwrap === 'function') {
return XPCNativeWrapper.unwrap(elem);
} else if (elem.wrappedJSObject) {
return elem.wrappedJSObject;
}
}
return elem;
}
win = unwrap(window);
// don't let blacklisted events get added by addEventListener
win.rEventBlacklist = rEventBlacklist;
win.oldAEL = win.Element.prototype.addEventListener; // store a reference to the original addEventListener
win.Element.prototype.addEventListener = function (name) {
if ( !window.rEventBlacklist.test(name) ) {
return window.oldAEL.apply(this, arguments);
}
};
function antiDisabler(event) {
var all = document.getElementsByTagName('*'),
doc = win.document,
body = win.document.body,
isPrototype = typeof doc.observe === 'function' && typeof doc.stopObserving === 'function',
len, e, i, jQall, jQdoc;
handlers_blacklist.forEach(function (event) {
doc[event] = null;
body.removeAttribute(event);
if (isPrototype === true) {
doc.stopObserving(event); // disable Prototype observation
}
});
body.style.MozUserSelect = 'text';
// Disabling of specific elements
for (i = 0, len = all.length; i < len; i += 1) {
e = unwrap( all[i] );
handlers_blacklist.forEach(function (event) {
e[event] = null;
e.removeAttribute(event);
});
if (e.style.MozUserSelect === 'none') {
e.style.MozUserSelect = 'text';
}
}
// Disabling by jQuery
var events_blacklist = handlers_blacklist.map(name => name.replace(/^on/i, ''));
// $
if (typeof win.$ === 'function' && typeof win.$.prototype.unbind === 'function') {
jQall = win.$('*');
jQdoc = win.$(doc);
events_blacklist.forEach(function (event) {
jQall.unbind(event);
jQdoc.unbind(event);
});
}
if (typeof win.$ === 'function' && typeof win.$.prototype.off === 'function') {
jQall = win.$('*');
jQdoc = win.$(doc);
events_blacklist.forEach(function (event) {
jQall.off(event);
jQdoc.off(event);
});
}
/*
if (typeof win.jQuery === 'function' && typeof win.jQuery.prototype.unbind === 'function') {
win.jQuery(win).unbind('keypress'); // Remove keyboard blocking - comment line out if you don't want it
}
*/
// jQuery
if (typeof win.jQuery === 'function' && typeof win.jQuery.prototype.unbind === 'function') {
jQall = win.jQuery('*');
jQdoc = win.jQuery(doc);
events_blacklist.forEach(function (event) {
jQall.unbind(event);
jQdoc.unbind(event);
});
}
if (typeof win.jQuery === 'function' && typeof win.jQuery.prototype.off === 'function') {
jQall = win.jQuery('*');
jQdoc = win.jQuery(doc);
events_blacklist.forEach(function (event) {
jQall.off(event);
jQdoc.off(event);
});
}
/*
if (typeof win.jQuery === 'function' && typeof win.jQuery.prototype.unbind === 'function') {
win.jQuery(win).unbind('keypress'); // Remove keyboard blocking - comment line out if you don't want it
}
*/
if (typeof win.ProtectImg !== 'undefined') {
win.ProtectImg = function () {
return true;
};
}
};
// remove other listeners when the page loads
JSL.runAt('interactive', antiDisabler);
JSL.runAt('complete', antiDisabler);
}());