Absolute Enable Right Click & Copy

Force Enable Right Click & Copy & Highlight

目前为 2018-02-25 提交的版本。查看 最新版本

  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 + `] Activate Absolute Right Click Mode To Force Remove Any Type Of Protection
  6. // @author Absolute
  7. // @version 1.5.0
  8. // @include *://*
  9. // @icon https://i.imgur.com/AC7SyUr.png
  10. // @compatible Chrome Google Chrome + Tampermonkey
  11. // @grant GM_registerMenuCommand
  12. // @license BSD
  13. // @copyright Absolute, All Right Reserved (2016-Oct-06)
  14. // @Exclude /.(/(^drive|w+|docs|translate).google.[a-z]|/www\.(youtube|facebook|instagram|bing|ebay|dropbox).com|(github|twitter|amazon|live).[^]).*/
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. var css = document.createElement('style');
  21. var head = document.head;
  22. head.appendChild(css);
  23.  
  24. css.type = 'text/css';
  25.  
  26. css.innerText = `* {
  27. -webkit-user-select: text !important;
  28. -moz-user-select: text !important;
  29. -ms-user-select: text !important;
  30. user-select: text !important;
  31. }`;
  32.  
  33. var elements = document.querySelectorAll('*');
  34.  
  35. for (var i = 0; i < elements.length; i++) {
  36. if (elements[i].style.userSelect == 'none') {
  37. elements[i].style.userSelect = 'auto';
  38. }
  39. }
  40.  
  41. var doc = document;
  42. var body = document.body;
  43.  
  44. var docEvents = [
  45. doc.oncontextmenu = null,
  46. doc.onselectstart = null,
  47. doc.ondragstart = null,
  48. doc.onmousedown = null
  49. ];
  50.  
  51. var bodyEvents = [
  52. body.oncontextmenu = null,
  53. body.onselectstart = null,
  54. body.ondragstart = null,
  55. body.onmousedown = null,
  56. body.oncut = null,
  57. body.oncopy = null,
  58. body.onpaste = null
  59. ];
  60.  
  61. setTimeout(function() {
  62. document.oncontextmenu = null;
  63. }, 2000);
  64.  
  65. [].forEach.call(
  66. ['copy', 'cut', 'paste', 'select', 'selectstart'],
  67. function(event) {
  68. document.addEventListener(event, function(e) { e.stopPropagation(); }, true);
  69. document.removeEventListener(event, this, true);
  70. }
  71. );
  72.  
  73. function keyPress(event) {
  74. if (event.ctrlKey && event.keyCode == 192) {
  75. return confirm('Activate Absolute Right Click Mode!') === true ? absoluteMod() : null;
  76. }
  77. }
  78.  
  79. function absoluteMod() {
  80. [].forEach.call(
  81. ['contextmenu', 'copy', 'cut', 'paste', 'mouseup', 'mousedown', 'keyup', 'keydown', 'drag', 'dragstart', 'select', 'selectstart'],
  82. function(event) {
  83. document.addEventListener(event, function(e) { e.stopPropagation(); }, true);
  84. document.removeEventListener(event, this, true);
  85. }
  86. );
  87. }
  88.  
  89. function alwaysAbsoluteMod() {
  90. let sites = ['example.com','www.example.com'];
  91. const list = RegExp(sites.join('|')).exec(location.hostname);
  92. return list ? absoluteMod() : null;
  93. }
  94.  
  95. setTimeout(function() {
  96. alwaysAbsoluteMod();
  97. enableCommandMenu();
  98. document.addEventListener('keydown', keyPress);
  99. }, 100);
  100.  
  101. function enableCommandMenu() {
  102. var commandMenu = true;
  103. if (commandMenu == true) {
  104. GM_registerMenuCommand('Enable Absolute Right Click Mode', absoluteMod);
  105. } else {
  106. return;
  107. }
  108. }
  109.  
  110. if (document.domain.match(/[^].(outlook.com|office.com|pcloud.com|box.com|sync.com|onedrive.com)/gi))
  111. return;
  112.  
  113. function EventsCall(callback) {
  114. this.events = ['DOMAttrModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMCharacterDataModified', 'DOMSubtreeModified'];
  115. this.bind();
  116. }
  117.  
  118. EventsCall.prototype.bind = function() {
  119. this.events.forEach(function (event) {
  120. document.addEventListener(event, this, true);
  121. }.bind(this));
  122. };
  123.  
  124. EventsCall.prototype.handleEvent = function() {
  125. this.isCalled = true;
  126. };
  127.  
  128. EventsCall.prototype.unbind = function() {
  129. this.events.forEach(function (event) {}.bind(this));
  130. };
  131.  
  132. function EventHandler(event) {
  133. this.event = event;
  134. this.contextmenuEvent = this.createEvent(this.event.type);
  135. }
  136.  
  137. EventHandler.prototype.createEvent = function(type) {
  138. var target = this.event.target;
  139. var event = target.ownerDocument.createEvent('MouseEvents');
  140. event.initMouseEvent(
  141. type, this.event.bubbles, this.event.cancelable,
  142. target.ownerDocument.defaultView, this.event.detail,
  143. this.event.screenX, this.event.screenY, this.event.clientX, this.event.clientY,
  144. this.event.ctrlKey, this.event.altKey, this.event.shiftKey, this.event.metaKey,
  145. this.event.button, this.event.relatedTarget
  146. );
  147. return event;
  148. };
  149.  
  150. EventHandler.prototype.fire = function() {
  151. var target = this.event.target;
  152. var contextmenuHandler = function(event) {
  153. event.preventDefault();
  154. }.bind(this);
  155. target.dispatchEvent(this.contextmenuEvent);
  156. this.isCanceled = this.contextmenuEvent.defaultPrevented;
  157. };
  158.  
  159. window.addEventListener('contextmenu', function handleEvent(event) {
  160. event.stopPropagation();
  161. event.stopImmediatePropagation();
  162. var handler = new EventHandler(event);
  163. window.removeEventListener(event.type, handleEvent, true);
  164. var EventsCallBback = new EventsCall(function() {});
  165. handler.fire();
  166. window.addEventListener(event.type, handleEvent, true);
  167. if (handler.isCanceled && (EventsCallBback.isCalled)) {
  168. event.preventDefault();
  169. }
  170. }, true);
  171.  
  172. })();
  173.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址