Greasy Fork is available in English.

Anti-Disabler

Restore context menus on sites that try to disable them

  1. // ==UserScript==
  2. // @name Anti-Disabler
  3. // @namespace https://greasyfork.org/ro/scripts/22444-anti-disabler / http://userscripts-mirror.org/scripts/review/30096
  4. // @description Restore context menus on sites that try to disable them
  5. // @include http://*
  6. // @include https://*
  7. // @exclude http://*.google.com/*
  8. // @exclude https://*.google.com/*
  9. // @exclude http://*.youtube.com/*
  10. // @exclude http://youtube.com/*
  11. // @exclude https://*.youtube.com/*
  12. // @exclude https://youtube.com/*
  13. // @exclude http://*.facebook.com/*
  14. // @exclude https://*.facebook.com/*
  15. // @exclude http://userscripts.org/*
  16. // @exclude https://userscripts.org/*
  17. // @exclude http://*.deviantart.com/*
  18. // @exclude http://www.jslint.com/*
  19. // @exclude https://www.jslint.com/*
  20. // @exclude file:///*/perf.html*
  21. // @exclude http://ninjakiwi.com/*
  22. // @exclude https://ninjakiwi.com/*
  23. // @exclude http://jsfiddle.net/*
  24. // @exclude https://jsfiddle.net/*
  25. // @exclude http://*.wikipedia.org/*
  26. // @exclude https://*.wikipedia.org/*
  27. // @require https://greasyfork.org/scripts/22443-joesimmons-library/code/JoeSimmons'%20Library.js
  28. // @copyright JoeSimmons & Mark Pilgrim
  29. // @version 1.1.3
  30. // @run-at document-start
  31. // ==/UserScript==
  32.  
  33. /* CHANGELOG
  34.  
  35. 1.1.3 (3/20/2014)
  36. - fixed a variable reference error
  37. - made the event blacklist regex case-insensitive
  38.  
  39. 1.1.2 (3/19/2014)
  40. - changed include to http and https protocols only
  41.  
  42. */
  43.  
  44.  
  45.  
  46. (function () {
  47.  
  48. 'use strict';
  49.  
  50. // Anti-Disabler modified by Joe Simmons
  51. /*
  52. Other mild credit:
  53. absurdlyobfuscated
  54. Jeroenz0r
  55. rinopo_d
  56. */
  57.  
  58. var events_blacklist = [
  59. 'onmousedown',
  60. 'onmouseup',
  61. 'oncontextmenu',
  62. 'oncopy',
  63. 'onselectstart',
  64. 'onselect',
  65. 'ondragstart',
  66. 'ondrag',
  67. 'ondragenter',
  68. 'ondragleave',
  69. 'ondragover',
  70. 'ondrop',
  71. 'ondragend'
  72. ],
  73. rEventBlacklist = new RegExp( events_blacklist.join('|').replace(/^on/g, ''), 'i' ),
  74. oldAEL, win;
  75.  
  76. // unwraps the element so we can use its methods freely
  77. function unwrap(elem) {
  78. if (elem) {
  79. if (typeof XPCNativeWrapper === 'function' && typeof XPCNativeWrapper.unwrap === 'function') {
  80. return XPCNativeWrapper.unwrap(elem);
  81. } else if (elem.wrappedJSObject) {
  82. return elem.wrappedJSObject;
  83. }
  84. }
  85.  
  86. return elem;
  87. }
  88.  
  89. win = unwrap(window);
  90.  
  91. // don't let blacklisted events get added by addEventListener
  92. oldAEL = win.Element.prototype.addEventListener; // store a reference to the original addEventListener
  93. win.Element.prototype.addEventListener = function () {
  94. if ( !rEventBlacklist.test(name) ) {
  95. return oldAEL.apply(this, arguments);
  96. }
  97. };
  98.  
  99. // remove other listeners when the page loads
  100. JSL.runAt('interactive', function (event) {
  101. var all = document.getElementsByTagName('*'),
  102. doc = win.document,
  103. body = win.document.body,
  104. isPrototype = typeof doc.observe === 'function' && typeof doc.stopObserving === 'function',
  105. len, e, i, jQall, jQdoc;
  106.  
  107. events_blacklist.forEach(function (event) {
  108. doc[event] = null;
  109. body.removeAttribute(event);
  110. if (isPrototype === true) {
  111. doc.stopObserving(event); // disable Prototype observation
  112. }
  113. });
  114.  
  115. // Disabling of specific elements
  116. for (i = 0, len = all.length; i < len; i += 1) {
  117.  
  118. e = unwrap( all[i] );
  119.  
  120. events_blacklist.forEach(function (event) {
  121. e[event] = null;
  122. e.removeAttribute(event);
  123. });
  124.  
  125. if (e.style.MozUserSelect === 'none') {
  126. e.style.MozUserSelect = 'text';
  127. }
  128.  
  129. }
  130.  
  131. // Disabling by jQuery
  132. if (typeof win.$ === 'function' && typeof win.$.prototype.unbind === 'function') {
  133. jQall = win.$('*');
  134. jQdoc = win.$(doc);
  135. events_blacklist.forEach(function (event) {
  136. jQall.unbind(event);
  137. jQdoc.unbind(event);
  138. });
  139. }
  140.  
  141. if (typeof win.jQuery === 'function' && typeof win.jQuery.prototype.unbind === 'function') {
  142. win.jQuery(win).unbind('keypress'); // Remove keyboard blocking - comment line out if you don't want it
  143. }
  144.  
  145. if (typeof win.ProtectImg !== 'undefined') {
  146. win.ProtectImg = function () {
  147. return true;
  148. };
  149. }
  150. });
  151.  
  152. }());