🔥🔥🔥文本选中复制(通用)🔥🔥🔥

文本选中复制通用版本,适用于大多数网站

目前为 2023-06-30 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 🔥🔥🔥文本选中复制(通用)🔥🔥🔥
  3. // @name:en Text Copy Universal
  4. // @name:zh-CN 🔥🔥🔥文本选中复制(通用)🔥🔥🔥
  5. // @description 文本选中复制通用版本,适用于大多数网站
  6. // @description:en Text copy general version, suitable for most websites.
  7. // @description:zh-CN 文本选中复制通用版本,适用于大多数网站
  8. // @namespace https://github.com/WindrunnerMax/TKScript
  9. // @version 1.1.2
  10. // @author Czy
  11. // @match http://*/*
  12. // @match https://*/*
  13. // @supportURL https://github.com/WindrunnerMax/TKScript/issues
  14. // @license GPL License
  15. // @run-at document-end
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_unregisterMenuCommand
  18. // @grant GM_notification
  19. // ==/UserScript==
  20. (function () {
  21. 'use strict';
  22.  
  23. function styleInject(css, ref) {
  24. if ( ref === void 0 ) ref = {};
  25. var insertAt = ref.insertAt;
  26.  
  27. if (!css || typeof document === 'undefined') { return; }
  28.  
  29. var head = document.head || document.getElementsByTagName('head')[0];
  30. var style = document.createElement('style');
  31. style.type = 'text/css';
  32.  
  33. if (insertAt === 'top') {
  34. if (head.firstChild) {
  35. head.insertBefore(style, head.firstChild);
  36. } else {
  37. head.appendChild(style);
  38. }
  39. } else {
  40. head.appendChild(style);
  41. }
  42.  
  43. if (style.styleSheet) {
  44. style.styleSheet.cssText = css;
  45. } else {
  46. style.appendChild(document.createTextNode(css));
  47. }
  48. }
  49.  
  50. var css_248z = ".__copy-currency-container{background-color:#4c98f7;border-radius:3px;bottom:0;display:flex;flex-direction:column;left:-150px;position:fixed;transition:all .3s;width:150px;z-index:9999999999}.__copy-currency-container:before{background-color:#4c98f7;border-radius:20px;content:\"\";cursor:pointer;height:20px;position:absolute;right:-6px;top:calc(50% - 10px);width:20px}.__copy-currency-container:hover{left:0}.__copy-currency-container>.__copy-currency-button{border:1px solid #fff;border-radius:3px;color:#fff!important;cursor:pointer;font-size:12px!important;margin:5px;padding:5px 3px 5px 4px;text-align:center;user-select:none;z-index:9999999999}";
  51. styleInject(css_248z);
  52.  
  53. const STORAGE_VALUE = {
  54. OPEN: "true",
  55. CLOSE: "false"
  56. };
  57. var BUTTON_STATUS = /* @__PURE__ */ ((BUTTON_STATUS2) => {
  58. BUTTON_STATUS2[BUTTON_STATUS2["OPEN"] = 0] = "OPEN";
  59. BUTTON_STATUS2[BUTTON_STATUS2["CLOSE"] = 1] = "CLOSE";
  60. return BUTTON_STATUS2;
  61. })(BUTTON_STATUS || {});
  62. const STORAGE_KEY_PREFIX = "copy-currency--";
  63. const register = (controllers) => {
  64. const container = document.createElement("div");
  65. container.className = "__copy-currency-container";
  66. document.body.appendChild(container);
  67. controllers.forEach((controller) => {
  68. const button = document.createElement("div");
  69. button.className = "__copy-currency-button";
  70. const localHookInfo = localStorage.getItem(STORAGE_KEY_PREFIX + controller.storageKey);
  71. controller.status = localHookInfo === STORAGE_VALUE.OPEN ? 1 /* CLOSE */ : 0 /* OPEN */;
  72. const handler = () => {
  73. if (controller.status === 1 /* CLOSE */) {
  74. controller.openFunction();
  75. controller.status = 0 /* OPEN */;
  76. button.textContent = controller.closeName;
  77. localStorage.setItem(
  78. STORAGE_KEY_PREFIX + controller.storageKey,
  79. STORAGE_VALUE.OPEN
  80. );
  81. } else {
  82. controller.closeFunction();
  83. controller.status = 1 /* CLOSE */;
  84. button.textContent = controller.openName;
  85. localStorage.setItem(
  86. STORAGE_KEY_PREFIX + controller.storageKey,
  87. STORAGE_VALUE.CLOSE
  88. );
  89. }
  90. };
  91. handler();
  92. button.addEventListener("click", handler);
  93. container.appendChild(button);
  94. });
  95. };
  96.  
  97. var utils = {
  98. insertCSS: (id, css) => {
  99. const style = document.createElement("style");
  100. style.id = id;
  101. style.innerHTML = css;
  102. const head = document.getElementsByTagName("head")[0];
  103. if (head) {
  104. head.appendChild(style);
  105. } else {
  106. window.onload = () => document.getElementsByTagName("head")[0].appendChild(style);
  107. }
  108. },
  109. removeCSS: (id) => {
  110. const style = document.getElementById(id);
  111. style && document.getElementsByTagName("head")[0].removeChild(style);
  112. }
  113. };
  114.  
  115. const stopNativePropagation = (event) => event.stopPropagation();
  116. const CONTROLLER_MAP = [
  117. {
  118. status: BUTTON_STATUS.CLOSE,
  119. storageKey: "selectstart-and-copy",
  120. openName: "✅ 启动解除复制限制",
  121. closeName: "❌ 关闭解除复制限制",
  122. openFunction: () => {
  123. window.addEventListener("selectstart", stopNativePropagation, true);
  124. window.addEventListener("copy", stopNativePropagation, true);
  125. utils.insertCSS(
  126. STORAGE_KEY_PREFIX + "selectstart-and-copy",
  127. "*{user-select: auto !important;-webkit-user-select: auto !important;}"
  128. );
  129. },
  130. closeFunction: () => {
  131. window.removeEventListener("selectstart", stopNativePropagation, true);
  132. window.removeEventListener("copy", stopNativePropagation, true);
  133. utils.removeCSS(STORAGE_KEY_PREFIX + "selectstart-and-copy");
  134. }
  135. },
  136. {
  137. status: BUTTON_STATUS.CLOSE,
  138. storageKey: "contextmenu",
  139. openName: "✅ 启动解除右键限制",
  140. closeName: "❌ 关闭解除右键限制",
  141. openFunction: () => window.addEventListener("contextmenu", stopNativePropagation, true),
  142. closeFunction: () => window.removeEventListener("contextmenu", stopNativePropagation, true)
  143. },
  144. {
  145. status: BUTTON_STATUS.CLOSE,
  146. storageKey: "keydown",
  147. openName: "✅ 启动解除键盘限制",
  148. closeName: "❌ 关闭解除键盘限制",
  149. openFunction: () => window.addEventListener("keydown", stopNativePropagation, true),
  150. closeFunction: () => window.removeEventListener("keydown", stopNativePropagation, true)
  151. }
  152. ];
  153. (function() {
  154. register(CONTROLLER_MAP);
  155. })();
  156.  
  157. })();

QingJ © 2025

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