Absolute Enable Right Click & Copy

Force Enable Right Click & Copy & Highlight

当前为 2018-08-21 提交的版本,查看 最新版本

  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.7
  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. }
  66. );
  67.  
  68. alwaysAbsoluteMode();
  69. enableCommandMenu();
  70. head.appendChild(css);
  71. document.addEventListener('keydown', keyPress);
  72.  
  73. }
  74.  
  75. function keyPress(event) {
  76. if (event.ctrlKey && event.keyCode == 192) {
  77. return confirm('Activate Absolute Right Click Mode!') == true ? absoluteMode() : null;
  78. }
  79. }
  80.  
  81. function absoluteMode() {
  82. [].forEach.call(
  83. ['contextmenu', 'copy', 'cut', 'paste', 'mouseup', 'mousedown', 'keyup', 'keydown', 'drag', 'dragstart', 'select', 'selectstart'],
  84. function(event) {
  85. document.addEventListener(event, function(e) { e.stopPropagation(); }, true);
  86. }
  87. );
  88. }
  89.  
  90. function alwaysAbsoluteMode() {
  91. let sites = ['example.com','www.example.com'];
  92. const list = RegExp(sites.join('|')).exec(location.hostname);
  93. return list ? absoluteMode() : null;
  94. }
  95.  
  96. function enableCommandMenu() {
  97. var commandMenu = true;
  98. try {
  99. if (typeof(GM_registerMenuCommand) == undefined) {
  100. return;
  101. } else {
  102. if (commandMenu == true ) {
  103. GM_registerMenuCommand('Enable Absolute Right Click Mode', function() {
  104. return confirm('Activate Absolute Right Click Mode!') == true ? absoluteMode() : null;
  105. });
  106. }
  107. }
  108. }
  109. catch(err) {
  110. console.log(err);
  111. }
  112. }
  113.  
  114. var blackList = [
  115. 'youtube.com','.google.','.google.com','greasyfork.org','twitter.com','instagram.com','facebook.com','translate.google.com','.amazon.','.ebay.','github.','stackoverflow.com',
  116. 'bing.com','live.com','.microsoft.com','dropbox.com','pcloud.com','box.com','sync.com','onedrive.com','mail.ru','deviantart.com','pastebin.com',
  117. 'dailymotion.com','twitch.tv','spotify.com','steam.com','steampowered.com','gitlab.com'
  118. ]
  119.  
  120. var enabled = false;
  121. var url = window.location.hostname;
  122. var match = RegExp(blackList.join('|')).exec(url);
  123.  
  124. if (window && typeof window != undefined && head != undefined) {
  125.  
  126. if (!match && enabled != true) {
  127.  
  128. main();
  129. enabled = true
  130.  
  131. //console.log(location.hostname);
  132.  
  133. window.addEventListener('contextmenu', function contextmenu(event) {
  134. event.stopPropagation();
  135. event.stopImmediatePropagation();
  136. var handler = new eventHandler(event);
  137. window.removeEventListener(event.type, contextmenu, true);
  138. var eventsCallBack = new eventsCall(function() {});
  139. handler.fire();
  140. window.addEventListener(event.type, contextmenu, true);
  141. if (handler.isCanceled && (eventsCallBack.isCalled)) {
  142. event.preventDefault();
  143. }
  144. }, true);
  145. }
  146.  
  147. function eventsCall() {
  148. this.events = ['DOMAttrModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMCharacterDataModified', 'DOMSubtreeModified'];
  149. this.bind();
  150. }
  151.  
  152. eventsCall.prototype.bind = function() {
  153. this.events.forEach(function (event) {
  154. document.addEventListener(event, this, true);
  155. }.bind(this));
  156. };
  157.  
  158. eventsCall.prototype.handleEvent = function() {
  159. this.isCalled = true;
  160. };
  161.  
  162. eventsCall.prototype.unbind = function() {
  163. this.events.forEach(function (event) {}.bind(this));
  164. };
  165.  
  166. function eventHandler(event) {
  167. this.event = event;
  168. this.contextmenuEvent = this.createEvent(this.event.type);
  169. }
  170.  
  171. eventHandler.prototype.createEvent = function(type) {
  172. var target = this.event.target;
  173. var event = target.ownerDocument.createEvent('MouseEvents');
  174. event.initMouseEvent(
  175. type, this.event.bubbles, this.event.cancelable,
  176. target.ownerDocument.defaultView, this.event.detail,
  177. this.event.screenX, this.event.screenY, this.event.clientX, this.event.clientY,
  178. this.event.ctrlKey, this.event.altKey, this.event.shiftKey, this.event.metaKey,
  179. this.event.button, this.event.relatedTarget
  180. );
  181. return event;
  182. };
  183.  
  184. eventHandler.prototype.fire = function() {
  185. var target = this.event.target;
  186. var contextmenuHandler = function(event) {
  187. event.preventDefault();
  188. }.bind(this);
  189. target.dispatchEvent(this.contextmenuEvent);
  190. this.isCanceled = this.contextmenuEvent.defaultPrevented;
  191. };
  192.  
  193. }
  194.  
  195. })();
  196.