Unlimit-Web

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

当前为 2025-02-18 提交的版本,查看 最新版本

  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 16.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 *://www.zhihu.com/*
  11. // @match *://blog.csdn.net/*
  12. // @match *://www.bilibili.com/*
  13. // @match *://www.cnblogs.com/*
  14. // @match *://www.360doc.com/*
  15. // @match *://blog.51cto.com/*
  16. // @match *://guofeng.yuedu.163.com/*
  17. // @match *://www.kuwo.cn/*
  18. // @match *://chuangshi.qq.com/*
  19. // @match *://read.qidian.com/*
  20. // @match *://dafrok.github.io/*
  21. // @match *://shushan.zhangyue.net/*
  22. // @match *://aqistudy.cn/*
  23. // @match *://www.xuexila.com/*
  24. // @match *://www.51test.net/*
  25. // @match *://www.laokaoya.com/*
  26. // @match *://utaten.com/*
  27. // @match *://book.qq.com/*
  28. // @match *://doc.mbalib.com/*
  29. // @match *://www.oh100.com/*
  30. // @match *://51test.net/*
  31. // @match *://www.cspengbo.com/*
  32. // @match *://www.diyifanwen.com/*
  33. // @match *://www.ahsrst.cn/*
  34. // @match *://kt250.com/*
  35. // @match *://*/*
  36. // @grant GM_getValue
  37. // @grant GM_setValue
  38. // @grant GM_registerMenuCommand
  39. // @grant GM_unregisterMenuCommand
  40. // @run-at document-end
  41. // ==/UserScript==
  42.  
  43. (function() {
  44. 'use strict';
  45.  
  46. const $ = (Selector, el) => (el || document).querySelector(Selector);
  47. const $$ = (Selector, el) => (el || document).querySelectorAll(Selector);
  48.  
  49. const muob = (Selector, el, func) => {
  50. const observer = new MutationObserver((mutationsList, observer2) => {
  51. for (let mutation of mutationsList) {
  52. if (mutation.type === 'childList') {
  53. const target = mutation.target.querySelector(Selector);
  54. if (target && !target.hasAttribute('data-duplicate')) {
  55. target.setAttribute('data-duplicate', 'true');
  56. func(target);
  57. }
  58. }
  59. }
  60. });
  61. observer.observe(el, {
  62. childList: true,
  63. subtree: true
  64. });
  65. };
  66.  
  67. /*黑名单: 需解除限制*/
  68. const block_list = {
  69. // 域名
  70. domain: {
  71. // 初始化,首次安装插件时使用此列表,之后使用插件存储的列表
  72. init: ["www.zhihu.com", "blog.csdn.net","www.bilibili.com","www.cnblogs.com","www.360doc.com","blog.51cto.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"],
  73. // 硬编码,除了使用插件存储的列表,每次也会使用此硬编码列表
  74. hard: [],
  75. },
  76. };
  77.  
  78. /*白名单: 指的是放行,无需解除限制*/
  79. const allow_list = {
  80. // 网页元素名称
  81. element: ['script', 'style', 'video'],
  82. // 网页元素id
  83. id: ['video'],
  84. // 网页元素className
  85. className: ['video'],
  86. };
  87.  
  88. const symbol = ["❎", "✅"];
  89. const symbol2 = ["未勾选", "已勾选"];
  90. let mc = [];
  91.  
  92. const sv = (key, value = "") => {
  93. GM_setValue(key, value);
  94. };
  95.  
  96. const gv = (key, value = "") => {
  97. return GM_getValue(key, value);
  98. };
  99.  
  100. /*枚举网页元素*/
  101. const eNumUnLimit = (EL = document) => {
  102. $$("*", EL).forEach(unLimit);
  103. try {
  104. console.clear = () => {};
  105. window.debugger = () => {};
  106. } catch (e) {
  107. }
  108. };
  109.  
  110. /*判断是否包含*/
  111. const isIn = (el, list, type) => {
  112. /*
  113. 例如 'video' 包含于 ['hello', 'video']
  114. 例如 'video' 模糊包含于 ['hello', 'good_player_top']
  115. 例如 'good_video_top' 特殊包含于 ['hello', 'video']
  116. */
  117. switch (type) {
  118. case 'fuzzy': // 模糊包含
  119. return list.some(item => item === el || item.includes(el));
  120. case 'fancy': // 特殊包含
  121. return list.some(item => item === el || el.includes(item));
  122. default: // 正常包含
  123. return list.some(item => item === el);
  124. }
  125. };
  126.  
  127. /*解除限制*/
  128. const unLimit = (el = null) => {
  129. if (
  130. isIn(el.nodeName.toLowerCase(), allow_list.element)
  131. || isIn(el.id?.toString().toLowerCase(), allow_list.id, 'fancy')
  132. || isIn(el.className?.toString().toLowerCase(), allow_list.className, 'fancy')
  133. ) return;
  134.  
  135. [
  136. "user-select", "-webkit-user-select", "-moz-user-select", "-ms-user-select", "-khtml-user-select",
  137. ].forEach(xcanwin => {
  138. const ec = el.childNodes;
  139. const j1 = ec && ec.length == 1 && ec[0] && ec[0].nodeType && ec[0].nodeType == 3;
  140. const style = document.defaultView.getComputedStyle(el, null)[xcanwin];
  141. const j2 = style && style != 'auto';
  142. if (j1 || j2){
  143. // 处理第一个子标签是text类型的标签 或者 处理select值被修改过的标签
  144. el.style.setProperty(xcanwin, "unset", "important");
  145. }
  146. });
  147.  
  148. [
  149. "onselect", "onselectstart", "onselectionchange",
  150. "oncopy", "onbeforecopy",
  151. "onpaste", "onbeforepaste", "oncut", "onbeforecut",
  152. "onpointercancel", "onpointerdown", "onpointerenter", "onpointerleave", "onpointerlockchange", "onpointerlockerror", "onpointermove", "onpointerout", "onpointerover", "onpointerrawupdate", "onpointerup",
  153. ].forEach(xcanwin => {
  154. el[xcanwin] = e => {
  155. // 处理能影响文本的事件
  156. e.stopImmediatePropagation();
  157. }
  158. });
  159.  
  160. [
  161. "onmouseenter", "onmousedown", "onmouseup", "onmouseout", "onmouseleave", "onmouseover",
  162. ].forEach(xcanwin => {
  163. el[xcanwin] = e => {
  164. if ([ "P" ].indexOf(e.target.nodeName) >=0 && e.button == 0) {
  165. // 处理单击左键和滑动左键下的html文本标签
  166. e.stopImmediatePropagation();
  167. }
  168. }
  169. });
  170.  
  171. [
  172. "onkeypress", "onkeyup", "onkeydown",
  173. ].forEach(xcanwin => {
  174. el[xcanwin] = e => {
  175. const keyCode = e.keyCode || e.which || e.charCode;
  176. const ctrlKey = e.ctrlKey || e.metaKey;
  177. if ((ctrlKey && keyCode == 67) || keyCode == 123) {
  178. // 处理ctrl+c和F12
  179. e.stopImmediatePropagation();
  180. }
  181. }
  182. });
  183.  
  184. [
  185. "oncontextmenu",
  186. ].forEach(xcanwin => {
  187. el[xcanwin] = e => {
  188. if (e.target && e.target.points == undefined){
  189. // 处理普通的单击右键,跳过滑动右键
  190. e.stopImmediatePropagation();
  191. }
  192. }
  193. });
  194. };
  195.  
  196. /*加入自动破解列表*/
  197. const switchAuto = (domain) => {
  198. let autolist = JSON.parse(gv("ul_autolist", "[]"));
  199. domain = domain ? domain : getdomain();
  200. if (isIn(domain, autolist)) {
  201. autolist = autolist.filter(el => el !== domain);
  202. } else {
  203. autolist.push(domain);
  204. }
  205. sv("ul_autolist", JSON.stringify(autolist));
  206. rmc();
  207. eNumUnLimit();
  208. };
  209.  
  210. /*查看自动破解列表*/
  211. const showAuto = () => {
  212. prompt("自动破解列表", gv("ul_autolist", "[]"));
  213. };
  214.  
  215. /*初始化自动破解列表*/
  216. const initAutoList = () => {
  217. const init = block_list.domain.init;
  218. //为空或者为[]时,说明首次运行,进行初始化
  219. if (gv("ul_autolist", "[]") === "[]") {
  220. sv("ul_autolist", JSON.stringify(init));
  221. }
  222. //解析移除时,进行初始化
  223. try {
  224. JSON.parse(gv("ul_autolist", "[]"));
  225. } catch (e) {
  226. sv("ul_autolist", JSON.stringify(init));
  227. }
  228. };
  229.  
  230. /*取消注册菜单*/
  231. const unrmc = () => {
  232. mc.forEach(x => GM_unregisterMenuCommand(x));
  233. };
  234.  
  235. /*注册菜单*/
  236. const rmc = () => {
  237. unrmc();
  238. let isauto;
  239. const autolist = JSON.parse(gv("ul_autolist", "[]"));
  240. const domain = getdomain();
  241. if (isIn(domain, autolist.concat(block_list.domain.hard))) {
  242. isauto = 1;
  243. } else {
  244. isauto = 0;
  245. }
  246. mc.push(GM_registerMenuCommand(`查看自动破解列表`, () => showAuto()));
  247. mc.push(GM_registerMenuCommand(`临时破解:${domain}`, () => eNumUnLimit()));
  248. mc.push(GM_registerMenuCommand(`自动破解:${domain} ${symbol[isauto]}${symbol2[isauto]}`, () => switchAuto(domain)));
  249. };
  250.  
  251. const getdomain = () => {
  252. return (new URL(location.href)).hostname;
  253. };
  254.  
  255. const main = () => {
  256. initAutoList();
  257. rmc();
  258. const autolist = JSON.parse(gv("ul_autolist", "[]"));
  259. const domain = getdomain();
  260. if (isIn(domain, autolist.concat(block_list.domain.hard))) {
  261. eNumUnLimit();
  262. setInterval(() => eNumUnLimit(), 3000);
  263. muob(`*`, $(`body`), unLimit);
  264. }
  265. };
  266.  
  267. main();
  268.  
  269. })();