Enable right click & Copy

Force Enable right click & Copy

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

  1. // ==UserScript==
  2. // @name Enable right click & Copy
  3. // @namespace Re-Enable right click Menu
  4. // @description Force Enable right click & Copy
  5. // @author Absolute
  6. // @version 0.1
  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 Menu
  17. document.body.addEventListener( "contextmenu", function(e) { e.stopPropagation(); } );
  18.  
  19. // Support to Enable right click
  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. (function() {
  40. 'use strict';
  41. var scriptTag = document.createElement('script');
  42. scriptTag.setAttribute('type', 'text/javascript');
  43. scriptTag.textContent = "$(function() {\n" + "$('body').off('copy contextmenu selectstart').unbind('contextmenu');\n" + "});";
  44. document.getElementsByTagName('body')[0].appendChild(scriptTag);
  45. [].forEach.call(document.querySelectorAll('[oncontextmenu]'),
  46. function (targetNode) {
  47. targetNode.removeAttribute('oncontextmenu');});
  48. [].forEach.call(document.querySelectorAll('[onselectstart="return false;"]'),
  49. function (targetNode) {
  50. targetNode.removeAttribute('onselectstart');});
  51. [].forEach.call(document.querySelectorAll('[onmousedown="return false;"]'),
  52. function (targetNode) {
  53. targetNode.removeAttribute('onselectstart');});
  54. [].forEach.call(document.querySelectorAll('[oncopy]'),
  55. function (targetNode) {
  56. targetNode.removeAttribute('oncopy');});
  57. [].forEach.call(document.querySelectorAll('[unselectable]'),
  58. function (targetNode) {
  59. targetNode.removeAttribute('unselectable');});
  60. if (document.onmousedown === 'rightclick') { document.onmousedown = ''; }
  61. if (document.oncontextmenu) { document.oncontextmenu = ''; }
  62. 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; }');}());
  63.  
  64.