Remove web limits (re-modified)

Pass to kill most of the site, you can lift the restrictions prohibited to copy, cut, select the text, right-click menu.

  1. // ==UserScript==
  2. // @namespace https://greatest.deepsurf.us/zh-CN/users/106222-qxin-i
  3.  
  4. // @name Remove web limits (re-modified)
  5. // @name:en Remove web limits (re-modified)
  6. // @name:zh 网页限制解除(改)
  7. // @name:zh-CN 网页限制解除(改)
  8. // @name:ja ウェブの規制緩和(変更)
  9.  
  10. // @author Cat73 & iqxin (Translated by CA)
  11. // @contributor iqxin & CA
  12.  
  13. // @description Pass to kill most of the site, you can lift the restrictions prohibited to copy, cut, select the text, right-click menu.
  14. // @description:en Pass to kill most of the site, you can lift the restrictions prohibited to copy, cut, select the text, right-click menu.
  15. // @description:zh 通杀大部分网站,可以解除禁止复制、剪切、选择文本、右键菜单的限制。原作者cat73,因为和搜索跳转脚本冲突,遂进行了改动,改为黑名单制。
  16. // @description:zh-CN 通杀大部分网站,可以解除禁止复制、剪切、选择文本、右键菜单的限制。原作者cat73,因为和搜索跳转脚本冲突,遂进行了改动,改为黑名单制。
  17. // @description:zh-TW 通殺大部分網站,可以解除禁止復制、剪切、選擇文本、右鍵菜單的限制。
  18. // @description:ja サイトのほとんどを殺すために渡し、あなたは、コピー切り取り、テキスト、右クリックメニューを選択することは禁止の制限を解除することができます。
  19.  
  20. // @description 原作者https://www.github.com/Cat7373/,因为和搜索跳转脚本冲突,遂进行了改动
  21. // @homepageURL https://cat7373.github.io/remove-web-limits/
  22. // @supportURL https://greatest.deepsurf.us/zh-CN/scripts/28497
  23.  
  24. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAABpElEQVR4nO3Vv2uUQRDG8c/ebSMWqay0trATAxrUSi1S2AiWFoJYpNCgoBjURsHWJKeNRfAvsDgFixQqKdPZ2ViEiCJYBOQu8f1hEXO59713j7MUfLZ6d2a/O8vMO0OzDnin9Ku2Mjvuaw07xgSAYEVXe2indMhj92zpKJLnBhF8MDeye9hn6zbN70eRiqCw02Bra3up8BBLu1FEBxsBucXqW4csz0ULe4jorSCMuPU89boRELDMHiI6Y8V65bbCUTccc70RkaOwKLOg0IkyXa9qTjOu2LAs6NZuD86hrdTyxRNTkUqqdhXlHrngGRVEZsMpJwex9DxIZSHYclesIb65LCoHgIs66UJq6btDBZHZrPh8V6YBOX66LbOkTGckBYimBW2FVTNeuOZNyrFJ236Yl4NSy5SbVm1PDvhodqgyMledTdRlAtDzqfL9tfkwUtyaRkv9LwFj9B/w7wPycXOhqlJ0yZHKPChMi5MCiM47XhsopbVJAUHfrYbmN/EToN+02eLPfz9OYyZhFJzW1Jn3lTsxaKQjCkp52jy45r1ZvSbTb9M0d4PBozGZAAAAAElFTkSuQmCC
  25.  
  26. // @version 4.1.4(en)
  27. // @license LGPLv3
  28.  
  29. // @compatible chrome Chrome_46.0.2490.86 + TamperMonkey + 脚本_1.3 测试通过
  30. // @compatible firefox Firefox_42.0 + GreaseMonkey + 脚本_1.2.1 测试通过
  31. // @compatible opera Opera_33.0.1990.115 + TamperMonkey + 脚本_1.1.3 测试通过
  32. // @compatible safari 未测试
  33.  
  34. // @match *://*/*
  35. // @exclude *www.bilibili.com/video*
  36. // @exclude *www.bilibili.com/bangumi*
  37. // @exclude *www.panda.tv*
  38.  
  39. // @connect eemm.me
  40. // @grant GM_getValue
  41. // @grant GM_setValue
  42. // @grant GM_addStyle
  43. // @grant GM_deleteValue
  44. // @grant GM_xmlhttpRequest
  45. // @grant GM_setClipboard
  46. // @run-at document-start
  47. // ==/UserScript==
  48. (function() {
  49. 'use strict';
  50.  
  51. var settingData = {
  52. "status":1,
  53. "version" : 0.1,
  54. "message" : "啦啦啦,啦啦啦,我是卖报的小行家",
  55. // "position" : ["0","0","auto"],
  56. "positionTop":"0",
  57. "positionLeft":"0",
  58. "positionRight":"auto",
  59. "addBtn" : true,
  60. "connectToTheServer" : true,
  61. "waitUpload":[],
  62. "currentURL":"null",
  63. // 域名规则列表
  64. "rules" : {
  65. "rule_def": {
  66. "name": "default",
  67. "hook_eventNames": "contextmenu|select|selectstart|copy|cut|dragstart|mousemove|beforeunload",
  68. "unhook_eventNames": "mousedown|mouseup|keydown|keyup",
  69. "dom0": true,
  70. "hook_addEventListener": true,
  71. "hook_preventDefault": true,
  72. "hook_set_returnValue": true,
  73. "add_css": true
  74. },
  75. "rule_plus": {
  76. "name": "default",
  77. "hook_eventNames": "contextmenu|select|selectstart|copy|cut|dragstart|mousedown|mouseup|mousemove|beforeunload",
  78. "unhook_eventNames": "keydown|keyup",
  79. "dom0": true,
  80. "hook_addEventListener": true,
  81. "hook_preventDefault": true,
  82. "hook_set_returnValue": true,
  83. "add_css": true
  84. },
  85. "rule_zhihu": {
  86. "name": "default",
  87. "hook_eventNames": "contextmenu|select|selectstart|copy|cut|dragstart|mousemove",
  88. "unhook_eventNames": "keydown|keyup",
  89. "dom0": true,
  90. "hook_addEventListener": true,
  91. "hook_preventDefault": true,
  92. "hook_set_returnValue": true,
  93. "add_css": true
  94. }
  95. },
  96. "data": [
  97. "b.faloo.com",
  98. "bbs.coocaa.com",
  99. "book.hjsm.tom.com",
  100. "book.zhulang.com",
  101. "book.zongheng.com",
  102. "chokstick.com",
  103. "chuangshi.qq.com",
  104. "city.udn.com",
  105. "cutelisa55.pixnet.net",
  106. "huayu.baidu.com",
  107. "imac.hk",
  108. "life.tw",
  109. "luxmuscles.com",
  110. "news.missevan.com",
  111. "read.qidian.com",
  112. "www.15yan.com",
  113. "www.17k.com",
  114. "www.18183.com",
  115. "www.360doc.com",
  116. "www.coco01.net",
  117. "www.eyu.com",
  118. "www.hongshu.com",
  119. "www.hongxiu.com",
  120. "www.imooc.com",
  121. "www.jjwxc.net",
  122. "www.readnovel.com",
  123. "www.tadu.com",
  124. "www.xxsy.net",
  125. "www.z3z4.com",
  126. "www.zhihu.com",
  127. "yuedu.163.com",
  128. "www.ppkao.com",
  129. "movie.douban.com",
  130. "www.ruiwen.com",
  131. "vipreader.qidian.com",
  132. "www.pigai.org",
  133. "www.shangc.net",
  134. "www.sdifen.com"
  135. ]
  136. }
  137.  
  138. var rwl_userData = null;
  139. var hostname = window.location.hostname;
  140. var btn_node = null;
  141. var rule = null;
  142. var list = null;
  143. // 储存名称
  144. var storageName = "iqxinStorageName";
  145. // 要处理的 event 列表
  146. var hook_eventNames, unhook_eventNames, eventNames;
  147. // 储存被 Hook 的函数
  148. var EventTarget_addEventListener = EventTarget.prototype.addEventListener;
  149. var document_addEventListener = document.addEventListener;
  150. var Event_preventDefault = Event.prototype.preventDefault;
  151.  
  152.  
  153. // 查看本地是否存在旧数据
  154. rwl_userData = GM_getValue("rwl_userData");
  155. if(!rwl_userData){
  156. rwl_userData = settingData
  157. // GM_setValue("rwl_userData",rwl_userData);
  158. }
  159.  
  160. version_up_3_to_4();
  161.  
  162. // 获取黑名单网站
  163. list = get_black_list();
  164.  
  165. // 添加按钮
  166. if(rwl_userData.addBtn){
  167. addBtn(); // 添加
  168. btn_node = document.getElementById("black_node");
  169. setTimeout(function(){
  170. try {
  171. dragBtn()
  172. } catch (e) {
  173. console.error("dragBtn函数 报错");
  174. }
  175. },1000)
  176. // dragBtn(); // 增加拖动事件
  177. }
  178.  
  179. // 检查是否在黑名单中
  180. if(check_black_list(list,hostname)){
  181. try {
  182. if(rwl_userData.addBtn){
  183. btn_node.checked = true;
  184. }
  185. } catch (e) {
  186. console.error("脚本rwl-错误:\n btn_node : %s\n%s\n脚本rwl-错误位置: btn_node.checked = true;",btn_node,e);
  187. } finally {
  188. init();
  189. }
  190. }
  191.  
  192.  
  193. // // ------------------------------函数 func
  194.  
  195. //添加按钮 func
  196. function addBtn(){
  197. var node = document.createElement("remove-web-limits-iqxin");
  198. node.id = "rwl-iqxin";
  199. node.className = "rwl-exempt";
  200.  
  201. // 再次打开窗口小于之前窗口的情况,导致按钮出现在可视窗口之外
  202. var screenClientHeight = document.documentElement.clientHeight;
  203. var tempHeight;
  204. if (rwl_userData.positionTop>screenClientHeight){
  205. tempHeight = screenClientHeight -40;
  206. } else{
  207. tempHeight = rwl_userData.positionTop;
  208. }
  209. // 改变窗口大小的情况
  210. window.onresize=function(){
  211. var screenClientHeight = document.documentElement.clientHeight;
  212. var tempHeight;
  213.  
  214. if (rwl_userData.positionTop>screenClientHeight){
  215. tempHeight = screenClientHeight -40;
  216. } else{
  217. tempHeight = rwl_userData.positionTop;
  218. }
  219.  
  220. node.style.top = tempHeight + "px";
  221. }
  222.  
  223. tempHeight = tempHeight<0?0:tempHeight
  224. node.style.cssText = "position:fixed;top:"+tempHeight+"px;left:"+rwl_userData.positionLeft+"px;right:"+rwl_userData.positionRight+"px;";
  225. // node.innerHTML = '<label><input type="checkbox" name="" id="black_node">黑名单</label><button id="delete">delete</btton>';
  226. // node.innerHTML = '<label>Restriction <input type="checkbox" name="" id="black_node"></label>';
  227. node.innerHTML = '<button type="button" id="rwl-setbtn"> set </button> <lalala style="cursor:move;">Restriction</lalala> <input type="checkbox" name="" id="black_node" >';
  228. if(window.self === window.top){
  229. if (document.querySelector("body")){
  230. document.body.appendChild(node);
  231. } else {
  232. document.documentElement.appendChild(node);
  233. }
  234. }
  235. node.addEventListener("mouseover",function(){
  236. node.classList.add("rwl-active-iqxin");
  237. });
  238. node.addEventListener("mouseleave",function(){
  239. setTimeout(function(){
  240. node.classList.remove("rwl-active-iqxin");
  241. black_check(black_node.checked);
  242. },100)
  243. });
  244.  
  245. var style = document.createElement("style");
  246. style.type="text/css";
  247. style.innerHTML = "#rwl-iqxin{" +
  248. "position:fixed;" +
  249. // "top:0;" +
  250. // "left:0px;" +
  251. "transform:translate(-90px,0);" +
  252. "width:95px;" +
  253. "height:25px;" +
  254. "font-size:12px;" +
  255. "font-weight: 500;" +
  256. "font-family:Verdana, Arial, '宋体';" +
  257. "color:#fff;" +
  258. "background:#333;" +
  259. "z-index:2147483647;" +
  260. "margin: 0;" +
  261. "opacity:0.05;" +
  262. "transition:0.3s;" +
  263. "overflow:hidden;" +
  264. "user-select:none;" +
  265. "text-align:center;" +
  266. "white-space:nowrap;" +
  267. "line-height:25px;" +
  268. "padding:0 16px;" +
  269. "border:1px solid #ccc;" +
  270. "border-width:1px 1px 1px 0;" +
  271. "border-bottom-right-radius:5px;" +
  272. "box-sizing: content-box;" +
  273. "}" +
  274. "#rwl-iqxin input{" +
  275. "margin: 0;" +
  276. "padding: 0;" +
  277. "vertical-align:middle;" +
  278. "-webkit-appearance:checkbox;" +
  279. "-moz-appearance:checkbox;" +
  280. "position: static;" +
  281. "clip: auto;" +
  282. "opacity: 1;" +
  283. "cursor: pointer;" +
  284. "}" +
  285. "#rwl-iqxin.rwl-active-iqxin{" +
  286. // "top: 10px;" +
  287. "left: 0px;" +
  288. "transform:translate(0,0);" +
  289. "opacity: 0.9;" +
  290. "height: 32px;" +
  291. "line-height: 32px" +
  292. "}" +
  293. "#rwl-iqxin label{" +
  294. "margin:0;" +
  295. "padding:0;" +
  296. "font-weight:500;" +
  297. "}" +
  298. "#rwl-iqxin button{" +
  299. "margin: 0;" +
  300. "padding: 0 2px;" +
  301. "border: none;" +
  302. "border-radius: 2px;" +
  303. "cursor: pointer;" +
  304. "}" +
  305. // 设置菜单
  306. "#rwl-setMenu{" +
  307. "text-align:left;" +
  308. "font-size:14px;" +
  309. "z-index:999999;" +
  310. "border: 1px solid cornflowerblue;" +
  311. "}" +
  312. "#rwl-setMenu p{" +
  313. "margin:5px auto;" +
  314. "}" +
  315. " ";
  316. document.querySelector("#rwl-iqxin").appendChild(style);
  317. };
  318.  
  319.  
  320. document.querySelector("#rwl-setbtn").addEventListener("click",function(){
  321. var oldEditBox = document.querySelector("#rwl-setMenu");
  322. if(oldEditBox){
  323. oldEditBox.parentNode.removeChild(oldEditBox);
  324. return;
  325. }
  326. var userSetting = GM_getValue("rwl_userData");
  327. var upload_checked = userSetting.connectToTheServer?"checked":"";
  328.  
  329. var odom = document.createElement("div");
  330. odom.id = "rwl-setMenu";
  331. odom.style.cssText ="position: absolute;" +
  332. "top: 50px;" +
  333. "left: 20px;" +
  334. "padding: 10px;" +
  335. "background: #fff;" +
  336. "border-radius: 4px;";
  337. var innerH = "" +
  338. "<p>Distance from top(in pixels) <input id='positiontop' type='text' value=" + userSetting.positionTop + "></p>" + "" +
  339. "<laberl> <p>Allow uploading blacklists<input id='uploadchecked' type='checkbox' " + upload_checked + "></p>" + "</laberl>" +
  340. "<textarea wrap='off' cols='45' rows='20' style='overflow:auto;border-radius:4px;'>" + JSON.stringify(userSetting.data,false,4) + "</textarea>" +
  341. "<br>" +
  342. // "<button id='rwl-reset'>清空设置</button> &nbsp;&nbsp;&nbsp;" +
  343. "<button id='rwl-setMenuSave'>Save</button> &nbsp;&nbsp;&nbsp;" +
  344. "<button id='rwl-setMenuClose' onclick='this.parentNode.parentNode.removeChild(this.parentNode);' >Close</button> &nbsp;&nbsp;&nbsp;" +
  345. // "<button id='rwl-codeboxsave'>Save</button>" +
  346. "<span style='font-size:0.7em;'>-- La la la,La la la, --</span>" +
  347. ""
  348. "";
  349. odom.innerHTML = innerH;
  350. document.body.appendChild(odom);
  351.  
  352. document.querySelector("#rwl-setMenuSave").addEventListener("click",saveSetting);
  353.  
  354. })
  355.  
  356. // 保存选项
  357. function saveSetting(){
  358. var positionTop = document.querySelector("#rwl-setMenu #positiontop").value;
  359. var uploadChecked = document.querySelector("#rwl-setMenu #uploadchecked").checked;
  360. var codevalue = document.querySelector("#rwl-setMenu textarea").value;
  361. // console.log(positionTop,uploadChecked);
  362. if(codevalue){
  363. console.log(JSON.parse(codevalue));
  364. var userSetting = GM_getValue("rwl_userData");
  365.  
  366. userSetting.data = JSON.parse(codevalue);
  367. userSetting.positionTop = parseInt(positionTop);
  368. userSetting.connectToTheServer = uploadChecked;
  369.  
  370. GM_setValue("rwl_userData",userSetting);
  371. // console.log(GM_getValue("searchEngineJumpData"));
  372. // 刷新页面
  373. setTimeout(function(){
  374. window.location.reload();
  375. },300);
  376. } else {
  377. alert("输入为空");
  378. // this.reset();
  379. }
  380. closeMenu();
  381. }
  382.  
  383. //关闭菜单
  384. function closeMenu(){
  385. var oldEditBox = document.querySelector("#rwl-setMenu");
  386. if(oldEditBox){
  387. oldEditBox.parentNode.removeChild(oldEditBox);
  388. return;
  389. }
  390. }
  391.  
  392. // 增加拖动事件 func
  393. function dragBtn(){
  394. var rwl_node = document.querySelector("#rwl-iqxin");
  395. // console.log(rwl_node);
  396. rwl_node.addEventListener("mousedown",function(event){
  397. rwl_node.style.transition = "null";
  398. var disX = event.clientX - rwl_node.offsetLeft;
  399. var disY = event.clientY - rwl_node.offsetTop;
  400.  
  401. var move = function(event){
  402. rwl_node.style.left = event.clientX - disX + "px" ;
  403. rwl_node.style.top = event.clientY - disY + "px" ;
  404. }
  405.  
  406. document.addEventListener("mousemove",move);
  407. document.addEventListener("mouseup",function(){
  408. rwl_node.style.transition = "0.3s";
  409. document.removeEventListener("mousemove",move);
  410. // 此函数内所有的注释语句都是有用的
  411. // 开启后,可拖动到屏幕右侧,但尚未添加css
  412. // 在上面添加 rwl-active-iqxin 的地方加上判断左右,在加上相应的css即可
  413. // 懒 2018-04-18 21:51:32
  414. // var bodyWidth = document.body.clientWidth;
  415. var rwl_nodeWidth = rwl_node.offsetLeft + rwl_node.offsetWidth/2;
  416. // if(rwl_nodeWidth > bodyWidth/2){
  417. // rwl_node.style.left = "auto";
  418. // rwl_node.style.right = 0;
  419. // rwl_userData.positionLeft = "auto";
  420. // rwl_userData.positionRight = "0";
  421. // } else {
  422. rwl_node.style.right = rwl_userData.positionRight = "auto";
  423. rwl_node.style.left = rwl_userData.positionLeft = 0;
  424. // }
  425. rwl_userData.positionTop = rwl_node.offsetTop;
  426. // console.log(rwl_userData);
  427. GM_setValue("rwl_userData",rwl_userData);
  428.  
  429. })
  430. })
  431. }
  432.  
  433. // 初始化 init func
  434. function init() {
  435. console.log("脚本-rwl-复制限制解除(改)------使用规则-----------------iqxin");
  436. // 针对个别网站采取不同的策略
  437. rule = clear();
  438. // 设置 event 列表
  439. hook_eventNames = rule.hook_eventNames.split("|");
  440. // TODO Allowed to return value
  441. unhook_eventNames = rule.unhook_eventNames.split("|");
  442. eventNames = hook_eventNames.concat(unhook_eventNames);
  443.  
  444. // 调用清理 DOM0 event 方法的循环
  445. if(rule.dom0) {
  446. setInterval(clearLoop, 5 * 1000);
  447. setTimeout(clearLoop, 1500);
  448. window.addEventListener('load', clearLoop, true);
  449. clearLoop();
  450. }
  451.  
  452. // hook addEventListener //导致搜索跳转失效的原因
  453. if(rule.hook_addEventListener) {
  454. EventTarget.prototype.addEventListener = addEventListener;
  455. document.addEventListener = addEventListener;
  456. }
  457.  
  458. // hook preventDefault
  459. if(rule.hook_preventDefault) {
  460. Event.prototype.preventDefault = function() {
  461. if(hook_eventNames.indexOf(this.type) < 0) {
  462. Event_preventDefault.apply(this, arguments);
  463. }
  464. };
  465. }
  466.  
  467. // Hook set returnValue
  468. if(rule.hook_set_returnValue) {
  469. Event.prototype.__defineSetter__('returnValue', function() {
  470. if(this.returnValue !== true && hook_eventNames.indexOf(this.type) >= 0) {
  471. this.returnValue = true;
  472. }
  473. });
  474. }
  475.  
  476. // 添加CSS // console.debug('url: ' + url, 'storageName:' + storageName, 'rule: ' + rule.name);
  477. if(rule.add_css) {
  478. GM_addStyle('html, :not([class*="rwl-exempt"]) {-webkit-user-select:text!important; -moz-user-select:text!important;} :not([class*="rwl-exempt"]) ::selection {color:#fff; background:#3390FF; !important;}');
  479. } //else {
  480. //GM_addStyle('html, :not([class*="rwl-exempt"]) {-webkit-user-select:text!important; -moz-user-select:text!important;}');
  481. //}
  482. }
  483.  
  484. // Hook addEventListener proc
  485. function addEventListener(type, func, useCapture) {
  486. var _addEventListener = this === document ? document_addEventListener : EventTarget_addEventListener;
  487. if(hook_eventNames.indexOf(type) >= 0) {
  488. _addEventListener.apply(this, [type, returnTrue, useCapture]);
  489. } else if(unhook_eventNames.indexOf(type) >= 0) {
  490. var funcsName = storageName + type + (useCapture ? 't' : 'f');
  491.  
  492. if(this[funcsName] === undefined) {
  493. this[funcsName] = [];
  494. _addEventListener.apply(this, [type, useCapture ? unhook_t : unhook_f, useCapture]);
  495. }
  496.  
  497. this[funcsName].push(func);
  498. } else {
  499. _addEventListener.apply(this, arguments);
  500. }
  501. }
  502.  
  503. // 清理循环
  504. function clearLoop() {
  505. rule = clear() // 对于动态生成的节点,随时检测
  506. var elements = getElements();
  507.  
  508. for(var i in elements) {
  509. for(var j in eventNames) {
  510. var name = 'on' + eventNames[j];
  511.  
  512. // ;?未解决
  513. // 2018-04-02 elements中会有字符串出现,原版不会,问题不明,根本原因尚未解决
  514. // 相关反馈 https://greatest.deepsurf.us/zh-CN/forum/discussion/36014
  515. // 问题版本号 v3.0.7
  516. // 问题补充 之前可以使用,具体版本未测(2018-04-02 21:27:53),原版可以使用
  517. if(Object.prototype.toString.call(elements[i])=="[object String]"){
  518. continue;
  519. }
  520.  
  521. if(elements[i][name] !== null && elements[i][name] !== onxxx) {
  522. if(unhook_eventNames.indexOf(eventNames[j]) >= 0) {
  523. elements[i][storageName + name] = elements[i][name];
  524. elements[i][name] = onxxx;
  525. } else {
  526. elements[i][name] = null;
  527. }
  528. }
  529. }
  530. }
  531. }
  532.  
  533. // 返回true的函数
  534. function returnTrue(e) {
  535. return true;
  536. }
  537. function unhook_t(e) {
  538. return unhook(e, this, storageName + e.type + 't');
  539. }
  540. function unhook_f(e) {
  541. return unhook(e, this, storageName + e.type + 'f');
  542. }
  543. function unhook(e, self, funcsName) {
  544. var list = self[funcsName];
  545. for(var i in list) {
  546. list[i](e);
  547. }
  548.  
  549. e.returnValue = true;
  550. return true;
  551. }
  552. function onxxx(e) {
  553. var name = storageName + 'on' + e.type;
  554. this[name](e);
  555.  
  556. e.returnValue = true;
  557. return true;
  558. }
  559.  
  560. // 获取所有元素 包括document
  561. function getElements() {
  562. var elements = Array.prototype.slice.call(document.getElementsByTagName('*'));
  563. elements.push(document);
  564. return elements;
  565. };
  566.  
  567. // 获取黑名单网站 Func
  568. function get_black_list(){
  569. // 之前版本可能导致存储空的字符串
  570. // 2018-06-11 15:11:44 保留,当容错处理
  571. var data_temp = rwl_userData.data;
  572. data_temp = data_temp.filter(function(item){
  573. return item.length>1;
  574. })
  575. return data_temp;
  576. }
  577. // 检查是否存在于黑名单中 返回位置 func
  578. function check_black_list(list,host){
  579. for(let i=0;i<list.length;i++){
  580. if(~hostname.indexOf(list[i])){
  581. return i+1; //万一匹配到第一个,返回0
  582. }
  583. }
  584. return false;
  585. }
  586.  
  587. // 鼠标点击后按钮后 检查是否在黑名单
  588. function black_check(bool){
  589. var list = GM_getValue("rwl_userData").data
  590. var check = check_black_list(list,hostname);
  591.  
  592. console.log(list)
  593.  
  594. if (bool && !check) {
  595. console.log(list);
  596. list = list.concat(hostname);
  597. console.log("选中 不在黑名单, 增加",hostname,list);
  598.  
  599. console.log("before: ",rwl_userData.waitUpload)
  600. rwl_userData.waitUpload.push(hostname); //准备上传
  601. rwl_userData.currentURL = window.location.href;
  602. console.log("after: ",rwl_userData.waitUpload)
  603.  
  604. saveData(list);
  605. init();
  606.  
  607. }else if(!bool && check){
  608. // console.log(check-1);
  609. console.log("check: ",check)
  610. list.splice(check-1,1);
  611. console.log("未选中 在黑名单, 刪除",list);
  612.  
  613. saveData(list);
  614.  
  615. // 刷新页面
  616. setTimeout(function(){
  617. window.location.reload(true);
  618. console.log("刷新页面loading");
  619. },350);
  620. }else{
  621. console.log("返回false");
  622. return false;
  623. }
  624. }
  625.  
  626. // 保存本地数据,并将数据上传至服务器
  627. function saveData(lists){
  628. console.log(lists);
  629. lists = lists.filter(function(item){
  630. return item.length>1;
  631. })
  632.  
  633. // 更新数据
  634. rwl_userData.data = lists.sort();
  635.  
  636. // 将本地黑名单上传
  637. if (rwl_userData.waitUpload.length > 0 && rwl_userData.connectToTheServer){
  638. // console.log("rwl : 上传...",rwl_userData.waitUpload);
  639. // console.log("rwl : 开始上传-----");
  640. GM_xmlhttpRequest({
  641. method: "POST",
  642. // url: "http://127.0.0.1:8000/tool/testajax/",
  643. url: "http://eemm.me/tool/rwl_upload/",
  644. data: JSON.stringify(rwl_userData),
  645. headers: {
  646. "Content-Type": "application/x-www-form-urlencoded"
  647. },
  648. onload: function(response) {
  649. // console.log("rwl : 上传成功----");
  650. }
  651. });
  652. rwl_userData.waitUpload = [];
  653. }
  654.  
  655. GM_setValue("rwl_userData",rwl_userData);
  656. // console.log(GM_getValue("rwl_userData"));
  657. return rwl_userData;
  658. }
  659.  
  660. // 数组去重
  661. function unique(arr) {
  662. var ret = []
  663. for (var i = 0; i < arr.length; i++) {
  664. var item = arr[i]
  665. if (ret.indexOf(item) === -1) {
  666. ret.push(item)
  667. }
  668. }
  669. return ret;
  670. }
  671.  
  672. // 复制到剪贴板
  673. function setClipboard(){
  674. var text_obj = window.getSelection();
  675. var text = text_obj.toString();
  676. GM_setClipboard(text);
  677.  
  678. }
  679.  
  680. // 部分网站采用了其他的防复制手段
  681. function clear(){
  682. // console.log("进入clear",hostname,rwl_userData.rules);
  683. switch (hostname){
  684. case "www.z3z4.com": clear_covers(".moviedownaddiv"); break;
  685. case "huayu.baidu.com": clear_covers("#jqContextMenu"); break;
  686. case "zhihu.com":
  687. case "www.zhihu.com": return rwl_userData.rules.rule_zhihu; break;
  688. case "t.bilibili.com": clear_link_bilibili(); break;
  689. case "www.shangc.net": return rwl_userData.rules.rule_plus; break;
  690. }
  691. return rwl_userData.rules.rule_def;
  692. }
  693. // 去除覆盖层
  694. function clear_covers(ele){
  695. var odiv = document.querySelector(ele);
  696. if(odiv){
  697. odiv.parentNode.removeChild(odiv);
  698. }
  699. }
  700. // b站将文字嵌套在链接中
  701. function clear_link_bilibili(){
  702. var odiv = document.querySelector(".description");
  703. // console.log(odiv);
  704. if(odiv){
  705. var tDiv = odiv.querySelector(".content-ellipsis");
  706. var aDiv = odiv.querySelector("a");
  707. // console.log(tDiv);
  708. // console.log(aDiv);
  709. odiv.appendChild(tDiv);
  710. }
  711. }
  712.  
  713. // 3.x.x 过渡 4.x.x 版本
  714. function version_up_3_to_4(){
  715. var old_version = GM_getValue("black_list");
  716. if(!old_version){return};
  717. rwl_userData.data = unique(rwl_userData.data.concat(old_version.data));
  718. GM_setValue("rwl_userData",rwl_userData);
  719.  
  720. GM_deleteValue("black_list");
  721. GM_deleteValue("rwl_userdata");
  722. }
  723. })();