网页限制解除(改)

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

La data de 03-08-2020. Vezi ultima versiune.

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