Absolute Enable Right Click & Copy Massive

Force Enable right click & Copy & Highlight

当前为 2016-10-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Absolute Enable Right Click & Copy Massive
  3. // @namespace Absolute Right Click
  4. // @description Force Enable right click & Copy & Highlight
  5. // @author Absolute
  6. // @version 1.2.3
  7. // @include http*://*
  8. // @icon https://cdn3.iconfinder.com/data/icons/communication-130/63/cursor-128.png
  9. // @license BSD
  10. // @copyright Absolute
  11. // @grant GM_addStyle
  12. // @Exclude /.*(JPG|PNG|GIF|JPEG|ico|bing|facebook|google|pixiv).*/
  13.  
  14. // ==/UserScript==
  15.  
  16. var Sites_List = ['163.com','www.site.com','www.site.com','www.site.com','www.site.com'];
  17.  
  18. (function GetSelection () {
  19. var style = document.createElement('style');
  20. var iStyle = '*{user-select: text !important;-webkit-user-select:text!important;}';
  21. style.type = 'text/css';
  22. if (style.styleSheet) { style.styleSheet.cssText = iStyle; }
  23. else { style.appendChild(document.createTextNode(iStyle)); }
  24. window.getSelection = null;
  25. document.oncontextmenu = null;
  26. document.body.setAttribute('oncopy','null');
  27. document.body.setAttribute('oncut','null');
  28. document.getElementsByTagName('head')[0].appendChild(style);
  29. })();
  30.  
  31. function Check (event) {
  32. if (event.stopPropagation) {
  33. event.stopPropagation();
  34. }}
  35. var events = ['NO-contextmenu','selectstart'];
  36. for (var i = 0; i < events.length; i++) {
  37. document['on'+events[i]] = Check;
  38. document.addEventListener(events[i], Check, true, true);
  39. }
  40.  
  41. (function RightClickButton() {
  42. function Mutation (callback) {
  43. this.isCalled = false;
  44. this.isUnbound = false;
  45. this.callback = callback;
  46. this.events = ['DOMAttrModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMCharacterDataModified', 'DOMSubtreeModified'];
  47. this.bind();
  48. }
  49. Mutation.prototype.bind = function () {
  50. this.events.forEach(function (name) {
  51. document.addEventListener(name, this, true);
  52. }.bind(this));
  53. };
  54. Mutation.prototype.handleEvent = function () {
  55. this.isCalled = true;
  56. this.unbind();
  57. };
  58. Mutation.prototype.unbind = function () {
  59. if (this.isUnbound) {
  60. return;
  61. }
  62. this.events.forEach(function (name) {
  63. document.removeEventListener(name, this, true);
  64. }.bind(this));
  65. this.isUnbound = true;
  66. };
  67. function Synchronizetion () {
  68. this._setTimeout = window.setTimeout;
  69. this._requestAnimationFrame = window.requestAnimationFrame;
  70. this._Promise = window.Promise;
  71. this.isRestoration = false;
  72. this.calledPromise = false;
  73. window.requestAnimationFrame = window.setTimeout = function (callback) {
  74. callback();
  75. };
  76. window.Promise = function () {
  77. this._Promise.apply(this, arguments);
  78. this.calledPromise = true;
  79. window.Promise = this._Promise;
  80. };}
  81. Synchronizetion.prototype.restore = function () {
  82. if (this.isRestoration) { return; }
  83. window.setTimeout = this._setTimeout;
  84. window.requestAnimationFrame = this._requestAnimationFrame;
  85. if (!this.calledPromise) {
  86. window.Promise = this._Promise;
  87. }
  88. this.isRestoration = true;
  89. };
  90. function EventHandler (event) {
  91. this.event = event;
  92. this.contextmenuEvent = this.createEvent(this.event.type);
  93. this.mouseupEvent = this.createEvent('mouseup');
  94. this.isCanceled = this.contextmenuEvent.defaultPrevented;
  95. }
  96. EventHandler.prototype.createEvent = function (type) {
  97. var target = this.event.target;
  98. var event = target.ownerDocument.createEvent('MouseEvents');
  99. event.initMouseEvent(type, this.event.bubbles, this.event.cancelable,
  100. target.ownerDocument.defaultView, this.event.detail,
  101. this.event.screenX, this.event.screenY, this.event.clientX, this.event.clientY,
  102. this.event.ctrlKey, this.event.altKey, this.event.shiftKey, this.event.metaKey,
  103. this.event.button, this.event.relatedTarget
  104. );return event;
  105. };
  106. EventHandler.prototype.fire = function () {
  107. var target = this.event.target;
  108. var contextmenuHandler = function (event) {
  109. this.isCanceled = event.defaultPrevented;
  110. event.preventDefault();
  111. }.bind(this);
  112. window.addEventListener(this.event.type, contextmenuHandler, false);
  113. target.dispatchEvent(this.contextmenuEvent);
  114. window.removeEventListener(this.event.type, contextmenuHandler, false);
  115. this.isCanceled = this.contextmenuEvent.defaultPrevented;
  116. target.dispatchEvent(this.mouseupEvent);
  117. };
  118. var disableRightClick = false;
  119. window.addEventListener('message', function (event) {
  120. if (event.data.type !== 'enable-right-click') { return; }
  121. disableRightClick = !!event.data.disableRightClick;
  122. event.stopPropagation();
  123. event.stopImmediatePropagation();
  124. }, true);
  125. window.addEventListener('contextmenu', handleEvent, true);
  126. function handleEvent (event) {
  127. if (disableRightClick) { return; }
  128. event.stopPropagation();
  129. event.stopImmediatePropagation();
  130. var handler = new EventHandler(event);
  131. window.removeEventListener(event.type, handleEvent, true);
  132. var sync = new Synchronizetion();
  133. var mutation = new Mutation(function () {
  134. sync.restore(); });
  135. var _alert = window.alert;
  136. window.alert = function () {};
  137. handler.fire();
  138. window.alert = _alert;
  139. sync.restore();
  140. mutation.unbind();
  141. window.addEventListener(event.type, handleEvent, true);
  142. if (handler.isCanceled && (mutation.isCalled || sync.calledPromise)) {
  143. event.preventDefault();
  144. }}})();
  145.  
  146. (function CheckSites () {
  147. var Check = window.location.href;
  148. var Match = RegExp(Sites_List.join('|')).exec(Check);
  149. if (Match) { Absolute_Mod (); }})();
  150.  
  151. function KeyPress (e) {
  152. if (e.altKey && e.ctrlKey) {
  153. alert("Absolute Right Click Mod Activate !!!");
  154. Absolute_Mod();}}
  155. document.addEventListener("keydown", KeyPress);
  156.  
  157. function Absolute_Mod () {
  158. document.addEventListener("copy",function(e){e.stopPropagation();},true);
  159. document.addEventListener("keyup",function(e){e.stopPropagation();},true);
  160. document.addEventListener("mouseup",function(e){e.stopPropagation();},true);
  161. document.addEventListener("keydown",function(e){e.stopPropagation();},true);
  162. document.addEventListener("mousedown",function(e){e.stopPropagation();},true);
  163. document.addEventListener("dragstart",function(e){e.stopPropagation();},true);
  164. document.addEventListener("mousedown",function(e) {e.stopPropagation();},true);
  165. document.addEventListener("contextmenu",function(e){e.stopPropagation();},true);
  166. document.addEventListener("selectstart",function(e){e.stopPropagation();},true);
  167. }
  168.  
  169.  
  170.