Greasy Fork is available in English.

网页限制解除(改)

通杀大部分网站,可以解除禁止复制、剪切、选择文本、右键菜单的限制。原作者cat73,因为和搜索跳转脚本冲突,遂进行了改动,改为黑名单制。

Per 18-05-2017. Zie de nieuwste versie.

  1. // ==UserScript==
  2. // @namespace https://greasyfork.org/zh-CN/users/106222-qxin-i
  3.  
  4. // @name 网页限制解除(改)
  5. // @name:en Remove web limits
  6. // @name:zh 网页限制解除
  7. // @name:ja ウェブの規制緩和
  8.  
  9. // @author Cat73&iqxin(修改)
  10.  
  11. // @description 通杀大部分网站,可以解除禁止复制、剪切、选择文本、右键菜单的限制。原作者cat73,因为和搜索跳转脚本冲突,遂进行了改动,改为黑名单制。
  12. // @description:en Pass to kill most of the site, you can lift the restrictions prohibited to copy, cut, select the text, right-click menu.
  13. // @description:zh 通杀大部分网站,可以解除禁止复制、剪切、选择文本、右键菜单的限制。原作者cat73,因为和搜索跳转脚本冲突,遂进行了改动,改为黑名单制。
  14. // @description:zh-CN 通杀大部分网站,可以解除禁止复制、剪切、选择文本、右键菜单的限制。原作者cat73,因为和搜索跳转脚本冲突,遂进行了改动,改为黑名单制。
  15. // @description:zh-TW 通殺大部分網站,可以解除禁止復制、剪切、選擇文本、右鍵菜單的限制。
  16. // @description:ja サイトのほとんどを殺すために渡し、あなたは、コピー切り取り、テキスト、右クリックメニューを選択することは禁止の制限を解除することができます。
  17.  
  18. // @description 原作者https://www.github.com/Cat7373/,因为和搜索跳转脚本冲突,遂进行了改动
  19. // @homepageURL https://cat7373.github.io/remove-web-limits/
  20. // @supportURL https://greasyfork.org/zh-CN/scripts/28497
  21.  
  22. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAABpElEQVR4nO3Vv2uUQRDG8c/ebSMWqay0trATAxrUSi1S2AiWFoJYpNCgoBjURsHWJKeNRfAvsDgFixQqKdPZ2ViEiCJYBOQu8f1hEXO59713j7MUfLZ6d2a/O8vMO0OzDnin9Ku2Mjvuaw07xgSAYEVXe2indMhj92zpKJLnBhF8MDeye9hn6zbN70eRiqCw02Bra3up8BBLu1FEBxsBucXqW4csz0ULe4jorSCMuPU89boRELDMHiI6Y8V65bbCUTccc70RkaOwKLOg0IkyXa9qTjOu2LAs6NZuD86hrdTyxRNTkUqqdhXlHrngGRVEZsMpJwex9DxIZSHYclesIb65LCoHgIs66UJq6btDBZHZrPh8V6YBOX66LbOkTGckBYimBW2FVTNeuOZNyrFJ236Yl4NSy5SbVm1PDvhodqgyMledTdRlAtDzqfL9tfkwUtyaRkv9LwFj9B/w7wPycXOhqlJ0yZHKPChMi5MCiM47XhsopbVJAUHfrYbmN/EToN+02eLPfz9OYyZhFJzW1Jn3lTsxaKQjCkp52jy45r1ZvSbTb9M0d4PBozGZAAAAAElFTkSuQmCC
  23.  
  24. // @version 2.4.0
  25. // @license LGPLv3
  26.  
  27. // @compatible chrome Chrome_46.0.2490.86 + TamperMonkey + 脚本_1.3 测试通过
  28. // @compatible firefox Firefox_42.0 + GreaseMonkey + 脚本_1.2.1 测试通过
  29. // @compatible opera Opera_33.0.1990.115 + TamperMonkey + 脚本_1.1.3 测试通过
  30. // @compatible safari 未测试
  31.  
  32. // @match *://*/*
  33. // @grant GM_getValue
  34. // @grant GM_setValue
  35. // @grant GM_addStyle
  36. // @grant GM_deleteValue
  37. // @run-at document-end
  38. // ==/UserScript==
  39. (function() {
  40. 'use strict';
  41.  
  42.  
  43.  
  44. //-------------------------------------------------------------------添加 start
  45. function test(){
  46. var black_list_user = GM_getValue("list_user");
  47. console.log(black_list_user);
  48. }
  49.  
  50. // 检查, 此處應將數組改為 Set 結構(2017-05-16,因為懶,所以不想動)
  51. function black_check(bool){
  52. var hostname = window.location.hostname;
  53. var check = check_black_list(list,hostname);
  54.  
  55. // console.log("check: ",check);
  56. // console.log(list);
  57.  
  58. if (bool && !check) {
  59. list = list.concat(hostname);
  60. // console.log("选中 不在黑名单, 增加",hostname,list);
  61. }else if(!bool && check){
  62. // console.log(check-1);
  63. list.splice(check-1,1);
  64. // console.log("未选中 在黑名单, 刪除",list);
  65. }else{
  66. // console.log("返回false");
  67. return false;
  68. }
  69.  
  70. // console.log(list);
  71. saveData(list);
  72. // test();
  73. // 刷新页面
  74. // window.location.reload(true);
  75. setTimeout(function(){
  76. window.location.reload(true);
  77. console.log("loading");
  78. },400);
  79. }
  80.  
  81. function saveData(list,version){
  82. // console.log(list);
  83. var userData = {
  84. "status":1,
  85. "version":black_list_version,
  86. "message":"0.1測試版,2017-05-16發佈",
  87. "data":list.sort()
  88. };
  89. GM_setValue("black_list",userData);
  90. // console.log(userData);
  91. console.log(GM_getValue("black_list"));
  92. return userData;
  93. }
  94.  
  95. // 數據庫版本升級,鑒於之前2.1.x版本只是隨手寫的,有太多的問題,保存數據未考慮周全,遂再次改動
  96. function versionUp(){
  97. var black_list;
  98. var black_list_user = GM_getValue("list_user");
  99. // var version2 = GM_getValue("black_list");
  100. // console.log(black_list_user);
  101. if(black_list_user){
  102. // 存在版本一,意味著從舊版升到新版
  103. black_list_user = black_list_user.split("|");
  104. black_list = Array.from( new Set(black_list_default.concat(black_list_user)));
  105.  
  106. // 刪除舊版本
  107. GM_deleteValue("list_user");
  108. } else {
  109. // 不存在版本一,也不存在版本二, 意味著新用戶
  110. black_list = black_list_default;
  111. }
  112.  
  113. // black_list.concat
  114.  
  115. // 保存數據
  116. return saveData(black_list);
  117. }
  118.  
  119. // 获取黑名单
  120. function get_black_list(){
  121.  
  122. var black_list = GM_getValue("black_list");
  123.  
  124. if(!black_list){
  125. black_list = versionUp();
  126. // black_list = GM_getValue("black_list");
  127. }
  128.  
  129. // 黑名單數據更新
  130. // console.log("本地黑名單版本: ",black_list.version, black_list_version)
  131. if(black_list.version < black_list_version){
  132. console.log("低版本,更新數據");
  133. var new_list = Array.from( new Set(black_list_default.concat(black_list.data)));
  134. black_list = saveData(new_list);
  135. }
  136.  
  137. // console.log(black_list);
  138. return black_list.data;
  139. }
  140. // 检查是否存在于黑名单中
  141. function check_black_list(list,host){
  142. for(let i=0;i<list.length;i++){
  143. // if(hostname===list[i]){
  144. if(~hostname.indexOf(list[i])){
  145. return i+1; //万一匹配到第一个,返回0
  146. }
  147. }
  148. return false;
  149. }
  150. //---------------------------------------------------------------------添加 end
  151. // 域名规则列表
  152. var rules = {
  153. black_rule: {
  154. name: "black",
  155. hook_eventNames: "",
  156. unhook_eventNames: ""
  157. },
  158. default_rule: {
  159. name: "default",
  160. hook_eventNames: "contextmenu|select|selectstart|copy|cut|dragstart",
  161. unhook_eventNames: "keydown|keyup|mousedown|mouseup",
  162. dom0: true,
  163. hook_addEventListener: true,
  164. hook_preventDefault: true,
  165. hook_set_returnValue: true,
  166. add_css: true
  167. },
  168. rule_plus: {
  169. name: "default",
  170. hook_eventNames: "contextmenu|select|selectstart|copy|cut|dragstart|mousedown|mouseup",
  171. unhook_eventNames: "keydown|keyup",
  172. dom0: true,
  173. hook_addEventListener: true,
  174. hook_preventDefault: true,
  175. hook_set_returnValue: true,
  176. add_css: true
  177. }
  178. };
  179.  
  180.  
  181. // 要处理的 event 列表
  182. var hook_eventNames, unhook_eventNames, eventNames;
  183. // 储存名称
  184. var storageName = getRandStr('qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM', parseInt(Math.random() * 12 + 8));
  185. // 储存被 Hook 的函数
  186. var EventTarget_addEventListener = EventTarget.prototype.addEventListener;
  187. var document_addEventListener = document.addEventListener;
  188. var Event_preventDefault = Event.prototype.preventDefault;
  189.  
  190. // Hook addEventListener proc
  191. function addEventListener(type, func, useCapture) {
  192. var _addEventListener = this === document ? document_addEventListener : EventTarget_addEventListener;
  193. if(hook_eventNames.indexOf(type) >= 0) {
  194. _addEventListener.apply(this, [type, returnTrue, useCapture]);
  195. } else if(unhook_eventNames.indexOf(type) >= 0) {
  196. var funcsName = storageName + type + (useCapture ? 't' : 'f');
  197.  
  198. if(this[funcsName] === undefined) {
  199. this[funcsName] = [];
  200. _addEventListener.apply(this, [type, useCapture ? unhook_t : unhook_f, useCapture]);
  201. }
  202.  
  203. this[funcsName].push(func);
  204. } else {
  205. _addEventListener.apply(this, arguments);
  206. }
  207. }
  208.  
  209. // 清理循环
  210. function clearLoop() {
  211. var elements = getElements();
  212.  
  213. for(var i in elements) {
  214. for(var j in eventNames) {
  215. var name = 'on' + eventNames[j];
  216. if(elements[i][name] !== null && elements[i][name] !== onxxx) {
  217. if(unhook_eventNames.indexOf(eventNames[j]) >= 0) {
  218. elements[i][storageName + name] = elements[i][name];
  219. elements[i][name] = onxxx;
  220. } else {
  221. elements[i][name] = null;
  222. }
  223. }
  224. }
  225. }
  226. }
  227.  
  228. // 返回true的函数
  229. function returnTrue(e) {
  230. return true;
  231. }
  232. function unhook_t(e) {
  233. return unhook(e, this, storageName + e.type + 't');
  234. }
  235. function unhook_f(e) {
  236. return unhook(e, this, storageName + e.type + 'f');
  237. }
  238. function unhook(e, self, funcsName) {
  239. var list = self[funcsName];
  240. for(var i in list) {
  241. list[i](e);
  242. }
  243.  
  244. e.returnValue = true;
  245. return true;
  246. }
  247. function onxxx(e) {
  248. var name = storageName + 'on' + e.type;
  249. this[name](e);
  250.  
  251. e.returnValue = true;
  252. return true;
  253. }
  254.  
  255. // 获取随机字符串
  256. function getRandStr(chs, len) {
  257. var str = '';
  258.  
  259. while(len--) {
  260. str += chs[parseInt(Math.random() * chs.length)];
  261. }
  262.  
  263. return str;
  264. }
  265.  
  266. // 获取所有元素 包括document
  267. function getElements() {
  268. // var elements = Array.prototype.slice.call(document.getElementsByTagName('*'));
  269. // console.log(elements);
  270.  
  271. // 添加子元素
  272. // console.log("添加子元");
  273. var oparent = document.querySelectorAll("[class*='rwl-exempt']");
  274. // console.log(oparent[0].getAttribute("rwl-exempt"));
  275. for(let i=0;i<oparent.length;i++){
  276. if (!oparent[i].getAttribute("rwl-exempt")) {
  277. // console.log("添加子元素,裏面");
  278. oparent[i].setAttribute("rwl-exempt","true");
  279. // [].forEach.call(oparent,function(odiv){
  280. var ochildren = oparent[i].querySelectorAll("*");
  281. [].forEach.call(ochildren,function(ochild){
  282. ochild.setAttribute("rwl-exempt","true");
  283. });
  284. // });
  285. }
  286. }
  287.  
  288. var elements = Array.prototype.slice.call(document.querySelectorAll("*:not([rwl-exempt='true'])"));
  289. // console.log(elements);
  290. elements.push(document);
  291. // console.log(elements);
  292.  
  293. return elements;
  294. }
  295.  
  296.  
  297. //添加按钮
  298. function addBtn(){
  299. var node = document.createElement("remove-web-limits-iqxin");
  300. node.id = "rwl-iqxin";
  301. node.className = "rwl-exempt";
  302. // node.innerHTML = '<label><input type="checkbox" name="" id="black_node">黑名单</label><button id="delete">delete</btton>';
  303. node.innerHTML = '<label>限制解除 <input type="checkbox" name="" id="black_node"></label>';
  304. if(window.self === window.top){
  305. if (document.querySelector("body")){
  306. document.body.appendChild(node);
  307. } else {
  308. document.documentElement.appendChild(node);
  309. }
  310. }
  311. node.addEventListener("mouseover",function(){
  312. node.classList.add("rwl-active-iqxin");
  313. // list = get_black_list();
  314. });
  315. node.addEventListener("mouseleave",function(){
  316. node.classList.remove("rwl-active-iqxin");
  317. black_check(black_node.checked);
  318. });
  319. // 删除本地存的黑名单
  320. // document.getElementById("delete").addEventListener("click",function(){
  321. // GM_deleteValue ("list_user");
  322. // test();
  323. // });
  324. GM_addStyle(
  325. "#rwl-iqxin{" +
  326. "position:fixed;" +
  327. "top:0;" +
  328. "left:-62px;" +
  329. "width:58px;" +
  330. "height:25px;" +
  331. "font-size:12px;" +
  332. "font-weight: 500;" +
  333. "font-family:Verdana, Arial, '宋体';" +
  334. "color:#fff;" +
  335. "background:#333;" +
  336. "z-index:2147483647;" +
  337. "margin: 0;" +
  338. "opacity:0.05;" +
  339. "transition:0.3s;" +
  340. "overflow:hidden;" +
  341. "user-select:none;" +
  342. "text-align:center;" +
  343. "white-space:nowrap;" +
  344. "line-height:25px;" +
  345. "padding:0 16px;" +
  346. "border:1px solid #ccc;" +
  347. "border-width:1px 1px 1px 0;" +
  348. "border-bottom-right-radius:5px;" +
  349. "box-sizing: content-box;" +
  350. "}" +
  351. "#rwl-iqxin input{" +
  352. "margin: 0;" +
  353. "padding: 0;" +
  354. "vertical-align:middle;" +
  355. "-webkit-appearance:checkbox;" +
  356. "-moz-appearance:checkbox;" +
  357. "position: static;" +
  358. "clip: auto;" +
  359. "opacity: 1;" +
  360. "}" +
  361. "#rwl-iqxin.rwl-active-iqxin{" +
  362. "top: 10px;" +
  363. "left: 0px;" +
  364. "opacity: 0.9;" +
  365. "height: 32px;" +
  366. "line-height: 32px" +
  367. "}" +
  368. "#rwl-iqxin label{" +
  369. "margin:0;" +
  370. "padding:0;" +
  371. "font-weight:500;" +
  372. "}"
  373. );
  374. };
  375.  
  376. // 部分网站采用了其他的防复制手段
  377. function clear(){
  378. // console.log(hostname);
  379. switch (hostname){
  380. case "www.z3z4.com": clear_z3z4(); break;
  381. case "huayu.baidu.com": clear_huayu(); break;
  382. // case "news.ifeng.com":
  383. // case "www.15yan.com": rule = clear_15yan();break;
  384. }
  385. return rules.rule_plus;
  386. }
  387. // www.z3z4.com 再三再四, 文字上面覆盖一层透明的div
  388. function clear_z3z4(){
  389. var oDiv = document.querySelector(".moviedownaddiv");
  390. if (oDiv) {
  391. oDiv.parentNode.removeChild(oDiv);
  392. }
  393. }
  394. function clear_huayu(){
  395. var oDiv = document.querySelector("#jqContextMenu");
  396. if (oDiv) {
  397. oDiv.parentNode.removeChild(oDiv);
  398. }
  399. }
  400. // www.15yan.com 15言, 监控 mousedown
  401. function clear_15yan(){
  402. return rules.rule_plus;
  403. }
  404.  
  405.  
  406. // 初始化
  407. function init() {
  408. // console.log("使用规则-------------------------------------------------iqxin");
  409. // 针对个别网站采取不同的策略
  410. var rule = clear();
  411. // 设置 event 列表
  412. hook_eventNames = rule.hook_eventNames.split("|");
  413. // TODO Allowed to return value
  414. unhook_eventNames = rule.unhook_eventNames.split("|");
  415. eventNames = hook_eventNames.concat(unhook_eventNames);
  416.  
  417. // 调用清理 DOM0 event 方法的循环
  418. if(rule.dom0) {
  419. setInterval(clearLoop, 30 * 1000);
  420. setTimeout(clearLoop, 2500);
  421. window.addEventListener('load', clearLoop, true);
  422. clearLoop();
  423. }
  424.  
  425. // hook addEventListener
  426. if(rule.hook_addEventListener) {
  427. EventTarget.prototype.addEventListener = addEventListener;
  428. document.addEventListener = addEventListener;
  429. }
  430.  
  431. // hook preventDefault
  432. if(rule.hook_preventDefault) {
  433. Event.prototype.preventDefault = function() {
  434. if(eventNames.indexOf(this.type) < 0) {
  435. Event_preventDefault.apply(this, arguments);
  436. }
  437. };
  438. }
  439.  
  440. // Hook set returnValue
  441. if(rule.hook_set_returnValue) {
  442. Event.prototype.__defineSetter__('returnValue', function() {
  443. if(this.returnValue !== true && eventNames.indexOf(this.type) >= 0) {
  444. this.returnValue = true;
  445. }
  446. });
  447. }
  448.  
  449. // console.debug('url: ' + url, 'storageName:' + storageName, 'rule: ' + rule.name);
  450.  
  451. // 添加CSS
  452. if(rule.add_css) {
  453. GM_addStyle('html, :not([rwl-exempt="true"]) {-webkit-user-select:text!important; -moz-user-select:text!important;}');
  454. }
  455.  
  456. }
  457.  
  458. //--开始执行---------------------------------------------------------------iqxin
  459. var black_list_version = 1.0;
  460. var black_list_default = [
  461. "b.faloo.com",
  462. "book.zhulang.com",
  463. "book.zongheng.com",
  464. "chokstick.com",
  465. "cutelisa55.pixnet.net",
  466. "huayu.baidu.com",
  467. "imac.hk",
  468. "life.tw",
  469. "news.missevan.com",
  470. "read.qidian.com",
  471. "www.15yan.com",
  472. "www.17k.com",
  473. "www.18183.com",
  474. "www.360doc.com",
  475. "www.coco01.net",
  476. "www.eyu.com",
  477. "www.hongshu.com",
  478. "www.hongxiu.com",
  479. "www.jjwxc.net",
  480. "www.readnovel.com",
  481. "www.tadu.com",
  482. "www.xxsy.net",
  483. "www.z3z4.com",
  484. "www.zhihu.com",
  485. "yuedu.163.com"
  486. ];
  487.  
  488. addBtn(); //页面左上角按钮,不想要按钮可以把这行注释掉
  489. var black_node = document.getElementById("black_node");
  490.  
  491. var list = get_black_list();
  492.  
  493. var hostname = window.location.hostname;
  494. if(check_black_list(list,hostname)){
  495. // 如果注释掉按钮,此处会获取不到
  496. if(black_node){
  497. black_node.checked = true;
  498. }
  499. //console.log("位于黑名单中----------------revove_web_limits------iqxin");
  500. init();
  501. }
  502. })();