Unlimit-Web

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

目前為 2025-02-09 提交的版本,檢視 最新版本

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