Absolute Enable Right Click & Copy

Force Enable Right Click & Copy & Highlight

目前为 2018-05-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.8.4
  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, 2016-Oct-06
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. var css = document.createElement('style');
  20. var head = document.head;
  21.  
  22. css.type = 'text/css';
  23.  
  24. css.innerText = `* {
  25. -webkit-user-select: text !important;
  26. -moz-user-select: text !important;
  27. -ms-user-select: text !important;
  28. user-select: text !important;
  29. }`;
  30.  
  31. var elements = document.querySelectorAll('*');
  32.  
  33. for (var i = 0; i < elements.length; i++) {
  34. if (elements[i].style.userSelect == 'none') {
  35. elements[i].style.userSelect = 'auto';
  36. }
  37. }
  38.  
  39. function main() {
  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. [].forEach.call(
  62. ['copy', 'cut', 'paste', 'select', 'selectstart'],
  63. function(event) {
  64. document.addEventListener(event, function(e) { e.stopPropagation(); }, true);
  65. document.removeEventListener(event, this, true);
  66. }
  67. );
  68.  
  69. alwaysAbsoluteMod();
  70. enableCommandMenu();
  71. head.appendChild(css);
  72. document.addEventListener('keydown', keyPress);
  73.  
  74. }
  75.  
  76. function keyPress(event) {
  77. if (event.ctrlKey && event.keyCode == 192) {
  78. return confirm('Activate Absolute Right Click Mode!') == true ? absoluteMod() : null;
  79. }
  80. }
  81.  
  82. function absoluteMod() {
  83. [].forEach.call(
  84. ['contextmenu', 'copy', 'cut', 'paste', 'mouseup', 'mousedown', 'keyup', 'keydown', 'drag', 'dragstart', 'select', 'selectstart'],
  85. function(event) {
  86. document.addEventListener(event, function(e) { e.stopPropagation(); }, true);
  87. document.removeEventListener(event, this, true);
  88. }
  89. );
  90. }
  91.  
  92. function alwaysAbsoluteMod() {
  93. let sites = ['example.com','www.example.com'];
  94. const list = RegExp(sites.join('|')).exec(location.hostname);
  95. return list ? absoluteMod() : null;
  96. }
  97.  
  98. function enableCommandMenu() {
  99. var commandMenu = true;
  100. if (commandMenu == true) {
  101. GM_registerMenuCommand('Enable Absolute Right Click Mode', function() {
  102. return confirm('Activate Absolute Right Click Mode!') == true ? absoluteMod() : null;
  103. });
  104. }
  105. }
  106.  
  107. var blackList = [
  108. 'youtube.com','.google.','.google.com','greasyfork.org','twitter.com','instagram.com','facebook.com','translate.google.com','.amazon.','.ebay.','github.','stackoverflow.com',
  109. 'bing.com','live.com','dropbox.com','pcloud.com','box.com','sync.com','onedrive.com','stackoverflow.com','mail.ru','deviantart.com','pastebin.com',
  110. 'dailymotion.com','twitch.tv','spotify.com','steam.com','steampowered.com','gitlab.com'
  111. ]
  112.  
  113. var enabled = false;
  114. var url = window.location.hostname;
  115. var match = RegExp(blackList.join('|')).exec(url);
  116.  
  117. if (window && typeof window != undefined && head != undefined) {
  118.  
  119. if (!match && enabled != true) {
  120.  
  121. main();
  122. enabled = true
  123.  
  124. //console.log(location.hostname);
  125.  
  126. window.addEventListener('contextmenu', function contextmenu(event) {
  127. event.stopPropagation();
  128. event.stopImmediatePropagation();
  129. var handler = new eventHandler(event);
  130. window.removeEventListener(event.type, contextmenu, true);
  131. var eventsCallBack = new eventsCall(function() {});
  132. handler.fire();
  133. window.addEventListener(event.type, contextmenu, true);
  134. if (handler.isCanceled && (eventsCallBack.isCalled)) {
  135. event.preventDefault();
  136. }
  137. }, true);
  138. }
  139.  
  140. function eventsCall() {
  141. this.events = ['DOMAttrModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMCharacterDataModified', 'DOMSubtreeModified'];
  142. this.bind();
  143. }
  144.  
  145. eventsCall.prototype.bind = function() {
  146. this.events.forEach(function (event) {
  147. document.addEventListener(event, this, true);
  148. }.bind(this));
  149. };
  150.  
  151. eventsCall.prototype.handleEvent = function() {
  152. this.isCalled = true;
  153. };
  154.  
  155. eventsCall.prototype.unbind = function() {
  156. this.events.forEach(function (event) {}.bind(this));
  157. };
  158.  
  159. function eventHandler(event) {
  160. this.event = event;
  161. this.contextmenuEvent = this.createEvent(this.event.type);
  162. }
  163.  
  164. eventHandler.prototype.createEvent = function(type) {
  165. var target = this.event.target;
  166. var event = target.ownerDocument.createEvent('MouseEvents');
  167. event.initMouseEvent(
  168. type, this.event.bubbles, this.event.cancelable,
  169. target.ownerDocument.defaultView, this.event.detail,
  170. this.event.screenX, this.event.screenY, this.event.clientX, this.event.clientY,
  171. this.event.ctrlKey, this.event.altKey, this.event.shiftKey, this.event.metaKey,
  172. this.event.button, this.event.relatedTarget
  173. );
  174. return event;
  175. };
  176.  
  177. eventHandler.prototype.fire = function() {
  178. var target = this.event.target;
  179. var contextmenuHandler = function(event) {
  180. event.preventDefault();
  181. }.bind(this);
  182. target.dispatchEvent(this.contextmenuEvent);
  183. this.isCanceled = this.contextmenuEvent.defaultPrevented;
  184. };
  185.  
  186. }
  187.  
  188. })();
  189.