Unlimit-Web

解除网页限制: 恢复文本的选中和复制, 过滤文本小尾巴, 恢复右键菜单. Remove webpage restrictions: restore the selection and copy of text, clear the text tail, and restore the right-click menu.

当前为 2024-01-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Unlimit-Web
  3. // @description 解除网页限制: 恢复文本的选中和复制, 过滤文本小尾巴, 恢复右键菜单. Remove webpage restrictions: restore the selection and copy of text, clear the text tail, and restore the right-click menu.
  4. // @version 9.1
  5. // @author xcanwin
  6. // @namespace https://github.com/xcanwin/Unlimit-Web/
  7. // @supportURL https://github.com/xcanwin/Unlimit-Web/
  8. // @icon data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" stroke-width="2" fill="none" stroke="currentColor"><path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"></path></svg>
  9. // @license GPL-2.0-only
  10. // @match *://blog.csdn.net/*
  11. // @match *://www.bilibili.com/*
  12. // @match *://www.360doc.com/*
  13. // @match *://guofeng.yuedu.163.com/*
  14. // @match *://www.kuwo.cn/*
  15. // @match *://chuangshi.qq.com/*
  16. // @match *://read.qidian.com/*
  17. // @match *://dafrok.github.io/*
  18. // @match *://shushan.zhangyue.net/*
  19. // @match *://aqistudy.cn/*
  20. // @match *://www.xuexila.com/*
  21. // @match *://www.51test.net/*
  22. // @match *://www.laokaoya.com/*
  23. // @match *://utaten.com/*
  24. // @match *://book.qq.com/*
  25. // @match *://doc.mbalib.com/*
  26. // @match *://www.oh100.com/*
  27. // @match *://51test.net/*
  28. // @match *://www.cspengbo.com/*
  29. // @match *://www.diyifanwen.com/*
  30. // @match *://www.ahsrst.cn/*
  31. // @match *://kt250.com/*
  32. // @match *://*/*
  33. // @grant GM_getValue
  34. // @grant GM_setValue
  35. // @grant GM_registerMenuCommand
  36. // @grant GM_unregisterMenuCommand
  37. // @run-at document-end
  38. // ==/UserScript==
  39.  
  40. (function() {
  41. 'use strict';
  42.  
  43. const $ = (Selector, el) => (el || document).querySelector(Selector);
  44. const $$ = (Selector, el) => (el || document).querySelectorAll(Selector);
  45.  
  46. const symbol = ["❌", "✔️"];
  47. const symbol2 = ["未勾选", "已勾选"];
  48. let mc = []
  49.  
  50. const sv = (key, value = "") => {
  51. GM_setValue(key, value);
  52. };
  53.  
  54. const gv = (key, value = "") => {
  55. return GM_getValue(key, value);
  56. };
  57.  
  58. const unLimit = () => {
  59. $$("*").forEach(el => {
  60. [
  61. "user-select", "-webkit-user-select", "-moz-user-select", "-ms-user-select", "-khtml-user-select", "pointer-events",
  62. ].forEach(xcanwin => {
  63. const ec = el.childNodes;
  64. const j1 = ec && ec.length == 1 && ec[0] && ec[0].nodeType && ec[0].nodeType == 3;
  65. const style = document.defaultView.getComputedStyle(el, null)[xcanwin];
  66. const j2 = style && style != 'auto';
  67. if (j1 || j2){
  68. // 处理第一个子标签是text类型的标签,处理select值被修改过的标签
  69. el.style.setProperty(xcanwin, "text", "important");
  70. }
  71. });
  72.  
  73. [
  74. "onselect", "onselectstart", "onselectionchange",
  75. "oncopy", "onbeforecopy",
  76. "onpaste", "onbeforepaste", "oncut", "onbeforecut",
  77. "onpointercancel", "onpointerdown", "onpointerenter", "onpointerleave", "onpointerlockchange", "onpointerlockerror", "onpointermove", "onpointerout", "onpointerover", "onpointerrawupdate", "onpointerup",
  78. ].forEach(xcanwin => {
  79. el[xcanwin] = e => {
  80. // 处理能影响文本的事件
  81. e.stopImmediatePropagation();
  82. }
  83. });
  84.  
  85. [
  86. "onmouseenter", "onmousedown", "onmouseup", "onmouseout", "onmouseleave", "onmouseover",
  87. ].forEach(xcanwin => {
  88. el[xcanwin] = e => {
  89. if ([ "P" ].indexOf(e.target.nodeName) >=0 && e.button == 0) {
  90. // 处理单击左键和滑动左键下的html文本标签
  91. e.stopImmediatePropagation();
  92. }
  93. }
  94. });
  95.  
  96. [
  97. "onkeypress", "onkeyup", "onkeydown",
  98. ].forEach(xcanwin => {
  99. el[xcanwin] = e => {
  100. const keyCode = e.keyCode || e.which || e.charCode;
  101. const ctrlKey = e.ctrlKey || e.metaKey;
  102. if ((ctrlKey && keyCode == 67) || keyCode == 123) {
  103. // 处理ctrl+c和F12
  104. e.stopImmediatePropagation();
  105. }
  106. }
  107. });
  108.  
  109. [
  110. "oncontextmenu",
  111. ].forEach(xcanwin => {
  112. el[xcanwin] = e => {
  113. if (e.target && e.target.points == undefined){
  114. // 处理普通的单击右键,跳过滑动右键
  115. e.stopImmediatePropagation();
  116. }
  117. }
  118. });
  119. });
  120.  
  121. try {
  122. console.clear = () => {};
  123. window.debugger = () => {};
  124. } catch (e) {
  125. }
  126. };
  127.  
  128. /*加入自动破解列表*/
  129. const switchAuto = (domain) => {
  130. let autolist = JSON.parse(gv("ul_autolist", "[]"));
  131. domain = domain ? domain : getdomain();
  132. if (autolist.includes(domain)) {
  133. autolist = autolist.filter(el => el !== domain);
  134. } else {
  135. autolist.push(domain);
  136. }
  137. sv("ul_autolist", JSON.stringify(autolist));
  138. rmc();
  139. unLimit();
  140. };
  141.  
  142. /*查看自动破解列表*/
  143. const showAuto = () => {
  144. prompt("自动破解列表", gv("ul_autolist", "[]"));
  145. };
  146.  
  147. /*初始化自动破解列表*/
  148. const initAutoList = () => {
  149. const defaultal = ["blog.csdn.net","www.bilibili.com","www.360doc.com","guofeng.yuedu.163.com","www.kuwo.cn","chuangshi.qq.com","read.qidian.com","dafrok.github.io","shushan.zhangyue.net","aqistudy.cn","www.xuexila.com","www.51test.net","www.laokaoya.com","utaten.com","book.qq.com","doc.mbalib.com","www.oh100.com","51test.net","www.cspengbo.com","www.diyifanwen.com","www.ahsrst.cn","kt250.com"];
  150. //为空或者为[]时,说明首次运行,进行初始化
  151. if (gv("ul_autolist", "[]") === "[]") {
  152. sv("ul_autolist", JSON.stringify(defaultal));
  153. }
  154. //解析移除时,进行初始化
  155. try {
  156. JSON.parse(gv("ul_autolist", "[]"));
  157. } catch (e) {
  158. sv("ul_autolist", JSON.stringify(defaultal));
  159. }
  160. };
  161.  
  162. /*取消注册菜单*/
  163. const unrmc = () => {
  164. mc.forEach(x => GM_unregisterMenuCommand(x));
  165. };
  166.  
  167. /*注册菜单*/
  168. const rmc = () => {
  169. unrmc();
  170. let isauto;
  171. const autolist = JSON.parse(gv("ul_autolist", "[]"));
  172. const domain = getdomain();
  173. if (autolist.includes(domain)) {
  174. isauto = 1;
  175. } else {
  176. isauto = 0;
  177. }
  178. mc.push(GM_registerMenuCommand(`查看自动破解列表`, showAuto));
  179. mc.push(GM_registerMenuCommand(`临时破解:${domain}`, unLimit));
  180. mc.push(GM_registerMenuCommand(`自动破解:${domain} ${symbol[isauto]}${symbol2[isauto]}`, () => switchAuto(domain)));
  181. };
  182.  
  183. const getdomain = () => {
  184. return (new URL(location.href)).hostname;
  185. };
  186.  
  187. const main = () => {
  188. initAutoList();
  189. rmc();
  190. const autolist = JSON.parse(gv("ul_autolist", "[]"));
  191. const domain = getdomain();
  192. if (autolist.includes(domain)) {
  193. unLimit();
  194. }
  195. };
  196.  
  197. main();
  198.  
  199. })();