Absolute Enable Right Click & Copy

Force Enable right click & Copy

目前为 2016-10-06 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Absolute Enable Right Click & Copy
  3. // @namespace Re-Enable right click Menu
  4. // @description Force Enable right click & Copy
  5. // @author Absolute
  6. // @version 1.1.2
  7. // @include http*://*
  8. ///@run-at document-start
  9. // @grant GM_addStyle
  10. // @icon https://cdn3.iconfinder.com/data/icons/communication-130/63/cursor-128.png
  11. // @Exclude http*://*.box.com/*
  12. // @Exclude /.*(JPG|PNG|GIF|JPEG|ico).*/
  13.  
  14. // ==/UserScript==
  15.  
  16. // Force Enable right click button
  17. document.body.addEventListener( "contextmenu", function(e) { e.stopPropagation(); } );
  18.  
  19. // Support to Enable Context Menu
  20. document.body.setAttribute('oncontextmenu', 'return true');
  21. document.body.setAttribute('onselectstart', 'return true');
  22. document.body.setAttribute('ondragstart', 'return true');
  23.  
  24. // Support to Enable Copy
  25. function clearEventListeners() {
  26. document.oncontextmenu = undefined;
  27. document.oncopy = undefined;
  28. document.oncut = undefined;
  29. document.onpaste = undefined;
  30. document.onselectstart = undefined;
  31. document.body.removeAttribute("oncopy");
  32. document.body.removeAttribute("ondrag");
  33. document.body.removeAttribute("oncontextmenu");
  34. document.body.removeAttribute("onselectstart");
  35. }
  36. window.addEventListener('load', clearEventListeners, false);
  37.  
  38. // Force Enable Copy & Highlight
  39. var scriptTag = document.createElement('script');
  40. scriptTag.setAttribute('type', 'text/javascript');
  41. scriptTag.textContent = "$(function() {\n" + "$('body').off('copy contextmenu selectstart').unbind('contextmenu');\n" + "});";
  42. document.getElementsByTagName('body')[0].appendChild(scriptTag);
  43. [].forEach.call(document.querySelectorAll('[oncontextmenu]'),
  44. function (targetNode) {
  45. targetNode.removeAttribute('oncontextmenu');});
  46. [].forEach.call(document.querySelectorAll('[onselectstart="return false;"]'),
  47. function (targetNode) {
  48. targetNode.removeAttribute('onselectstart');});
  49. [].forEach.call(document.querySelectorAll('[onmousedown="return false;"]'),
  50. function (targetNode) {
  51. targetNode.removeAttribute('onselectstart');});
  52. [].forEach.call(document.querySelectorAll('[oncopy]'),
  53. function (targetNode) {
  54. targetNode.removeAttribute('oncopy');});
  55. [].forEach.call(document.querySelectorAll('[unselectable]'),
  56. function (targetNode) {
  57. targetNode.removeAttribute('unselectable');});
  58. if (document.onmousedown === 'rightclick') { document.onmousedown = ''; }
  59. if (document.oncontextmenu) { document.oncontextmenu = ''; }
  60. 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; }');
  61.  
  62.  
  63.