USERSCRIPT : Remove Web Limits


SUBMITTED BY: alvinbonifachu

DATE: Sept. 24, 2018, 10:03 p.m.

FORMAT: Text only

SIZE: 26.8 kB

HITS: 199

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

comments powered by Disqus