Absolute Enable Right Click & Copy

Force Enable Right Click & Copy & Highlight

当前为 2017-12-07 提交的版本,查看 最新版本

  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.4.6
  8. // @include http://*
  9. // @include https://*
  10. // @icon https://i.imgur.com/Iq9LtC4.png
  11. // @compatible Chrome Google Chrome + Tampermonkey
  12. // @license BSD
  13. // @copyright Absolute, All Right Reserved (2016-Oct-06)
  14. // @Exclude /.[^].(github.com|Zgoogle.[^]|youtube.com|facebook.com|instagram.com|twitter.com|bing.com|live.com|amazon.[^]|ebay.com|dropbox.com).*/
  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. document.body.oncontextmenu = null;
  64. }, 2000);
  65.  
  66. [].forEach.call(
  67. ['copy', 'cut', 'paste', 'select', 'selectstart'],
  68. function(event) {
  69. document.addEventListener(event, function(e) { e.stopPropagation(); }, true);
  70. document.removeEventListener(event, this, true);
  71. }
  72. );
  73.  
  74. function keyPress(event) {
  75. if (event.ctrlKey && event.keyCode == 192) {
  76. return confirm("Activate Absolute Right Click Mode!") === true ? absoluteMod() : null;
  77. }
  78. }
  79.  
  80. function absoluteMod() {
  81. [].forEach.call(
  82. ['contextmenu', 'copy', 'cut', 'paste', 'mouseup', 'mousedown', 'keyup', 'keydown', 'drag', 'dragstart', 'select', 'selectstart'],
  83. function(event) {
  84. document.addEventListener(event, function(e) { e.stopPropagation(); }, true);
  85. document.removeEventListener(event, this, true);
  86. }
  87. );
  88. }
  89.  
  90. function alwaysAbsoluteMod() {
  91. let sites = ['example.com','www.example.com'];
  92. const list = RegExp(sites.join('|')).exec(location.hostname);
  93. return list ? absoluteMod() : null;
  94. }
  95.  
  96. setTimeout(function() {
  97. alwaysAbsoluteMod();
  98. document.addEventListener("keydown", keyPress);
  99. }, 100);
  100.  
  101. if (location.hostname.match(/[^].(outlook.com|office.com|pcloud.com|box.com|sync.com|onedrive.com)/gi))
  102. return;
  103.  
  104. function EventsCall(callback) {
  105. this.events = ['DOMAttrModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMCharacterDataModified', 'DOMSubtreeModified'];
  106. this.bind();
  107. }
  108.  
  109. EventsCall.prototype.bind = function() {
  110. this.events.forEach(function (event) {
  111. document.addEventListener(event, this, true);
  112. }.bind(this));
  113. };
  114.  
  115. EventsCall.prototype.handleEvent = function() {
  116. this.isCalled = true;
  117. };
  118.  
  119. EventsCall.prototype.unbind = function() {
  120. this.events.forEach(function (event) {}.bind(this));
  121. };
  122.  
  123. function EventHandler(event) {
  124. this.event = event;
  125. this.contextmenuEvent = this.createEvent(this.event.type);
  126. }
  127.  
  128. EventHandler.prototype.createEvent = function(type) {
  129. var target = this.event.target;
  130. var event = target.ownerDocument.createEvent('MouseEvents');
  131. event.initMouseEvent(
  132. type, this.event.bubbles, this.event.cancelable,
  133. target.ownerDocument.defaultView, this.event.detail,
  134. this.event.screenX, this.event.screenY, this.event.clientX, this.event.clientY,
  135. this.event.ctrlKey, this.event.altKey, this.event.shiftKey, this.event.metaKey,
  136. this.event.button, this.event.relatedTarget
  137. );
  138. return event;
  139. };
  140.  
  141. EventHandler.prototype.fire = function() {
  142. var target = this.event.target;
  143. var contextmenuHandler = function(event) {
  144. event.preventDefault();
  145. }.bind(this);
  146. target.dispatchEvent(this.contextmenuEvent);
  147. this.isCanceled = this.contextmenuEvent.defaultPrevented;
  148. };
  149.  
  150. window.addEventListener('contextmenu', function handleEvent(event) {
  151. event.stopPropagation();
  152. event.stopImmediatePropagation();
  153. var handler = new EventHandler(event);
  154. window.removeEventListener(event.type, handleEvent, true);
  155. var EventsCallBback = new EventsCall(function() {});
  156. handler.fire();
  157. window.addEventListener(event.type, handleEvent, true);
  158. if (handler.isCanceled && (EventsCallBback.isCalled)) {
  159. event.preventDefault();
  160. } else {
  161. return;
  162. }
  163. }, true);
  164.  
  165. })();
  166.