Advertisement
BigBisous

Anti-Disabler

Dec 13th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Anti-Disabler
  3. // @namespace      http://diveintomark.org/projects/greasemonkey/
  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. // @downloadURL    http://userscripts.org/scripts/source/30096.user.js
  28. // @updateURL      http://userscripts.org/scripts/source/30096.meta.js
  29. // @require        https://raw.github.com/joesimmons/jsl/master/versions/jsl-1.3.0.js
  30. // @copyright      JoeSimmons & Mark Pilgrim
  31. // @version        1.1.3
  32. // @run-at         document-start
  33. // ==/UserScript==
  34.  
  35. /* CHANGELOG
  36.  
  37. 1.1.3 (3/20/2014)
  38.     - fixed a variable reference error
  39.     - made the event blacklist regex case-insensitive
  40.  
  41. 1.1.2 (3/19/2014)
  42.     - changed include to http and https protocols only
  43.  
  44. */
  45.  
  46.  
  47.  
  48. (function () {
  49.  
  50.     'use strict';
  51.  
  52.     // Anti-Disabler modified by Joe Simmons
  53.     /*
  54.     Other mild credit:
  55.         absurdlyobfuscated
  56.         Jeroenz0r
  57.         rinopo_d
  58.     */
  59.  
  60.     var events_blacklist = [
  61.             'onmousedown',
  62.             'onmouseup',
  63.             'oncontextmenu',
  64.             'onselectstart',
  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. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement