Absolute Enable Right Click & Copy

Force Enable Right Click & Copy & Highlight

目前为 2018-06-14 提交的版本。查看 最新版本

  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.6
  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. alwaysAbsoluteMod();
  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 ? absoluteMod() : null;
  78. }
  79. }
  80.  
  81. function absoluteMod() {
  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 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. function enableCommandMenu() {
  97. var commandMenu = true;
  98. if (commandMenu == true) {
  99. GM_registerMenuCommand('Enable Absolute Right Click Mode', function() {
  100. return confirm('Activate Absolute Right Click Mode!') == true ? absoluteMod() : null;
  101. });
  102. }
  103. }
  104.  
  105. var blackList = [
  106. 'youtube.com','.google.','.google.com','gf.qytechs.cn','twitter.com','instagram.com','facebook.com','translate.google.com','.amazon.','.ebay.','github.','stackoverflow.com',
  107. 'bing.com','live.com','dropbox.com','pcloud.com','box.com','sync.com','onedrive.com','mail.ru','deviantart.com','pastebin.com',
  108. 'dailymotion.com','twitch.tv','spotify.com','steam.com','steampowered.com','gitlab.com'
  109. ]
  110.  
  111. var enabled = false;
  112. var url = window.location.hostname;
  113. var match = RegExp(blackList.join('|')).exec(url);
  114.  
  115. if (window && typeof window != undefined && head != undefined) {
  116.  
  117. if (!match && enabled != true) {
  118.  
  119. main();
  120. enabled = true
  121.  
  122. //console.log(location.hostname);
  123.  
  124. window.addEventListener('contextmenu', function contextmenu(event) {
  125. event.stopPropagation();
  126. event.stopImmediatePropagation();
  127. var handler = new eventHandler(event);
  128. window.removeEventListener(event.type, contextmenu, true);
  129. var eventsCallBack = new eventsCall(function() {});
  130. handler.fire();
  131. window.addEventListener(event.type, contextmenu, true);
  132. if (handler.isCanceled && (eventsCallBack.isCalled)) {
  133. event.preventDefault();
  134. }
  135. }, true);
  136. }
  137.  
  138. function eventsCall() {
  139. this.events = ['DOMAttrModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMCharacterDataModified', 'DOMSubtreeModified'];
  140. this.bind();
  141. }
  142.  
  143. eventsCall.prototype.bind = function() {
  144. this.events.forEach(function (event) {
  145. document.addEventListener(event, this, true);
  146. }.bind(this));
  147. };
  148.  
  149. eventsCall.prototype.handleEvent = function() {
  150. this.isCalled = true;
  151. };
  152.  
  153. eventsCall.prototype.unbind = function() {
  154. this.events.forEach(function (event) {}.bind(this));
  155. };
  156.  
  157. function eventHandler(event) {
  158. this.event = event;
  159. this.contextmenuEvent = this.createEvent(this.event.type);
  160. }
  161.  
  162. eventHandler.prototype.createEvent = function(type) {
  163. var target = this.event.target;
  164. var event = target.ownerDocument.createEvent('MouseEvents');
  165. event.initMouseEvent(
  166. type, this.event.bubbles, this.event.cancelable,
  167. target.ownerDocument.defaultView, this.event.detail,
  168. this.event.screenX, this.event.screenY, this.event.clientX, this.event.clientY,
  169. this.event.ctrlKey, this.event.altKey, this.event.shiftKey, this.event.metaKey,
  170. this.event.button, this.event.relatedTarget
  171. );
  172. return event;
  173. };
  174.  
  175. eventHandler.prototype.fire = function() {
  176. var target = this.event.target;
  177. var contextmenuHandler = function(event) {
  178. event.preventDefault();
  179. }.bind(this);
  180. target.dispatchEvent(this.contextmenuEvent);
  181. this.isCanceled = this.contextmenuEvent.defaultPrevented;
  182. };
  183.  
  184. }
  185.  
  186. })();
  187.  

QingJ © 2025

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