Absolute Enable Right Click & Copy

Force Enable Right Click & Copy & Highlight

当前为 2016-11-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Absolute Enable Right Click & Copy
  3. // @namespace Absolute Right Click
  4. // @description Force Enable Right Click & Copy & Highlight
  5. // @shortcutKeys [Ctrl + Alt] Activate Absolute Right Click Mod To Force Remove Any Type Of Protection
  6. // @author Absolute
  7. // @version 1.2.7
  8. // @include *
  9. // @icon https://cdn3.iconfinder.com/data/icons/communication-130/63/cursor-128.png
  10. // @license BSD
  11. // @copyright Absolute, All Right Reserved (2016)
  12. // @grant GM_addStyle
  13. // @Exclude /.*(www.google.[^]|bing.com|facebook.com|pixiv.net).*/
  14.  
  15. // ==/UserScript==
  16.  
  17. var Sites_List = ['163.com','www.site.com','www.site.com','www.site.com'];
  18.  
  19. (function GetSelection () {
  20. var style = document.createElement('style');
  21. var iStyle = '*{user-select:text!important;-webkit-user-select:text!important;}';
  22. style.type = 'text/css';
  23. if (style.styleSheet) {
  24. style.styleSheet.cssText = iStyle; }
  25. else { style.appendChild(document.createTextNode(iStyle)); }
  26. window.getSelection = null;
  27. document.oncontextmenu = null;
  28. document.getElementsByTagName('head')[0].appendChild(style);
  29. })();
  30.  
  31. (function CheckEvents () {
  32. var events = ['oncut','oncopy','ondragstart','onselectstart','oncontextmenu'];
  33. for (var i = 0; i < events.length; i++)
  34. document.body.setAttribute(events[i],'null');
  35. })();
  36.  
  37. (function FixEvents () {
  38. var events = ['contextmenu'];
  39. for (var i = 0; i < events.length; i++) {
  40. document.addEventListener(events[i],function(e){e.stopPropagation();});
  41. document.addEventListener(events[i],function(e){e.stopImmediatePropagation();});
  42. }})();
  43.  
  44. (function RightClickButton () {
  45. function EventsCall (callback) {
  46. this.isCalled = false;
  47. this.isUnbound = false;
  48. this.callback = callback;
  49. this.events = ['DOMAttrModified','DOMNodeInserted','DOMNodeRemoved','DOMCharacterDataModified','DOMSubtreeModified'];
  50. this.bind();
  51. }
  52. EventsCall.prototype.bind = function () {
  53. this.events.forEach(function (event) {
  54. document.addEventListener(event, this, true);
  55. }.bind(this));
  56. };
  57. EventsCall.prototype.handleEvent = function () {
  58. this.isCalled = true;
  59. this.unbind();
  60. };
  61. EventsCall.prototype.unbind = function () {
  62. if (this.isUnbound) {
  63. return;
  64. }
  65. this.events.forEach(function (event) {
  66. document.removeEventListener(event, this, true);
  67. }.bind(this));
  68. this.isUnbound = true;
  69. };
  70. function Synchronization () {
  71. }
  72. Synchronization.prototype.restore = function () {
  73. this.isRestoration = true;
  74. };
  75. function EventHandler (event) {
  76. this.event = event;
  77. this.contextmenuEvent = this.createEvent(this.event.type);
  78. }
  79. EventHandler.prototype.createEvent = function (type) {
  80. var target = this.event.target;
  81. var event = target.ownerDocument.createEvent('MouseEvents');
  82. event.initMouseEvent(type, this.event.bubbles, this.event.cancelable,
  83. target.ownerDocument.defaultView, this.event.detail,
  84. this.event.screenX, this.event.screenY, this.event.clientX, this.event.clientY,
  85. this.event.ctrlKey, this.event.altKey, this.event.shiftKey, this.event.metaKey,
  86. this.event.button, this.event.relatedTarget);
  87. return event;
  88. };
  89. EventHandler.prototype.fire = function () {
  90. var target = this.event.target;
  91. var contextmenuHandler = function (event) {
  92. event.preventDefault();
  93. }.bind(this);
  94. window.addEventListener(this.event.type, contextmenuHandler, false);
  95. target.dispatchEvent(this.contextmenuEvent);
  96. window.removeEventListener(this.event.type, contextmenuHandler, false);
  97. this.isCanceled = this.contextmenuEvent.defaultPrevented;
  98. };
  99. window.addEventListener('contextmenu', handleEvent, true);
  100. function handleEvent (event) {
  101. event.stopPropagation();
  102. event.stopImmediatePropagation();
  103. var handler = new EventHandler(event);
  104. window.removeEventListener(event.type, handleEvent, true);
  105. var sync = new Synchronization();
  106. var EventsCallBback = new EventsCall(function () {
  107. sync.restore();
  108. });
  109. handler.fire();
  110. window.addEventListener(event.type, handleEvent, true);
  111. if (handler.isCanceled && (EventsCallBback.isCalled)) {
  112. event.preventDefault();
  113. }}})();
  114.  
  115. (function CheckIncludeSites () {
  116. var Check = window.location.href;
  117. var Match = RegExp(Sites_List.join('|')).exec(Check);
  118. if (Match) { Absolute_Mod(); }
  119. })();
  120.  
  121. function KeyPress (e) {
  122. if (e.altKey && e.ctrlKey) {
  123. alert("Absolute Right Click Mod Activate !");
  124. Absolute_Mod();}}
  125. document.addEventListener("keydown", KeyPress);
  126.  
  127. function Absolute_Mod () {
  128. var events = ['contextmenu','copy','mouseup','mousedown','keyup','keydown','dragstart','selectstart'];
  129. for (var i = 0; i < events.length; i++) {
  130. document.addEventListener(events[i],function(e){e.stopPropagation();},true);
  131. }}