Disable 'disable right click'

Disables the ugly feature that disables right click

当前为 2016-07-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Disable 'disable right click'
  3. // @namespace https://github.com/mosaicer
  4. // @author mosaicer
  5. // @description Disables the ugly feature that disables right click
  6. // @version 1.4
  7. // @include *
  8. // @run-at document-end
  9. // @grant GM_addStyle
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13.  
  14. var scriptTag = document.createElement('script');
  15.  
  16. scriptTag.setAttribute('type', 'text/javascript');
  17. scriptTag.textContent = "$(function() {\n" +
  18. // " $('[oncontextmenu]').removeAttr('oncontextmenu');\n" +
  19. // " $('[onselectstart=\"return false;\"]').removeAttr('onselectstart');\n" +
  20. // " $('[onmousedown=\"return false;\"]').removeAttr('onmousedown');\n" +
  21. // " $('[oncopy]').removeAttr('oncopy');\n" +
  22. // " $('[unselectable]').removeAttr('unselectable');\n" +
  23. " $('body').off('copy contextmenu selectstart').unbind('contextmenu');\n" +
  24. "});";
  25.  
  26. document.getElementsByTagName('body')[0].appendChild(scriptTag);
  27.  
  28. [].forEach.call(document.querySelectorAll('[oncontextmenu]'),
  29. function (targetNode) {
  30. targetNode.removeAttribute('oncontextmenu');
  31. }
  32. );
  33.  
  34. [].forEach.call(document.querySelectorAll('[onselectstart="return false;"]'),
  35. function (targetNode) {
  36. targetNode.removeAttribute('onselectstart');
  37. }
  38. );
  39.  
  40. [].forEach.call(document.querySelectorAll('[onmousedown="return false;"]'),
  41. function (targetNode) {
  42. targetNode.removeAttribute('onselectstart');
  43. }
  44. );
  45.  
  46. [].forEach.call(document.querySelectorAll('[oncopy]'),
  47. function (targetNode) {
  48. targetNode.removeAttribute('oncopy');
  49. }
  50. );
  51.  
  52. [].forEach.call(document.querySelectorAll('[unselectable]'),
  53. function (targetNode) {
  54. targetNode.removeAttribute('unselectable');
  55. }
  56. );
  57.  
  58. if (document.onmousedown === 'rightclick') {
  59. document.onmousedown = '';
  60. }
  61.  
  62. if (document.oncontextmenu) {
  63. document.oncontextmenu = '';
  64. }
  65.  
  66. GM_addStyle('* {user-select: text !important; -moz-user-select: text !important; -webkit-user-select: text !important; -webkit-user-drag: text !important; -khtml-user-select: text !important; -khtml-user-drag: text !important; pointer-events: auto !important;}');
  67. }());