remove the posts which make you sick

移除贴吧讨厌鬼的帖子

目前为 2015-07-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name remove the posts which make you sick
  3. // @author burningall
  4. // @description 移除贴吧讨厌鬼的帖子
  5. // @version 2015.7.5.3.0
  6. // @include *tieba.baidu.com/p/*
  7. // @include *tieba.baidu.com/*
  8. // @include *tieba.baidu.com/f?*
  9. // @grant GM_addStyle
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_listValues
  13. // @grant GM_deleteValue
  14. // @compatible firefox 性能稍微不足
  15. // @compatible chrome 推荐
  16. // @license The MIT License (MIT); http://opensource.org/licenses/MIT
  17. // @supportURL http://www.burningall.com
  18. // @contributionURL troy450409405@gmail.com|alipay.com
  19. // @namespace https://gf.qytechs.cn/zh-CN/users/3400-axetroy
  20. // ==/UserScript==
  21.  
  22. //============快捷键==========
  23. //【Ctrl】+【F3】-----调出控制面板
  24. //============样式区==========
  25. var style='\
  26. body{\
  27. -webkit-backface-visibility: hidden;\
  28. }\
  29. /*给body添加滤镜*/\
  30. .blur{\
  31. -webkit-filter: blur(5px) grayscale();\
  32. -moz-filter: blur(5px) grayscale();\
  33. -o-filter: blur(5px) grayscale();\
  34. -ms-filter: blur(5px) grayscale();\
  35. filter: blur(5px) grayscale();\
  36. }\
  37. #pannal-troy{\
  38. width:200px;\
  39. height:auto;\
  40. background:#303030;\
  41. color:#fff;\
  42. position:fixed;\
  43. z-index:1000000000;\
  44. text-align:center;\
  45. }\
  46. #pannal-troy>div{\
  47. margin:10px 0;\
  48. }\
  49. #pannal-troy input{\
  50. color:#3e3e3e;\
  51. }\
  52. #pannal-troy h3{\
  53. color:rgb(0, 255, 226);\
  54. }\
  55. #pannal-setting input[type=range]{\
  56. width:80%;\
  57. }\
  58. #fn input{\
  59. padding:5px;\
  60. margin:0 5px;\
  61. border:none;\
  62. cursor:pointer;\
  63. }\
  64. #fn input:hover{\
  65. background:#2A959D;\
  66. color:#fff;\
  67. }\
  68. #pannal-troy>span{\
  69. position:absolute;\
  70. padding:0 10px;\
  71. top:0;\
  72. right:0;\
  73. cursor:pointer;\
  74. opacity:0.8;\
  75. background:#fff;\
  76. color:#303030;\
  77. }\
  78. #blockWay{\
  79. color:#3e3e3e;\
  80. border:none;\
  81. }\
  82. /*控制面板遮罩层*/\
  83. #mars{\
  84. position:fixed;\
  85. width:100%;\
  86. height:100%;\
  87. background:rgba(155, 155, 155,0.5);\
  88. top:0;\
  89. left:0;\
  90. z-index:999999999;\
  91. }\
  92. /*屏蔽模板遮罩层*/\
  93. .mar{\
  94. position:absolute;\
  95. top:0;\
  96. left:0;\
  97. z-index:999999998;\
  98. -webkit-backface-visibilityhidden;\
  99. }\
  100. #showList{\
  101. position:relative;\
  102. overflow-y:auto;\
  103. overflow-x:hidden;\
  104. width:100%;\
  105. height:93%;\
  106. }\
  107. #list{\
  108. position:absolute;\
  109. width:0;\
  110. height:20px;\
  111. top:-10px;\
  112. left:200px;\
  113. background:#303030;\
  114. overflow:hidden;\
  115. }\
  116. #showList>li{\
  117. width:100%;\
  118. height:18px;\
  119. clear:both;\
  120. margin:10px 0;\
  121. cursor:pointer;\
  122. }\
  123. #showList>li:hover{\
  124. background-color:#54A19E;\
  125. color:#303030;\
  126. }\
  127. .key{\
  128. float:left;\
  129. clear:both;\
  130. margin-left:10px;\
  131. width:120px;\
  132. text-align:left;\
  133. overflow:hidden;\
  134. text-overflow:ellipsis;\
  135. white-space:nowrap;\
  136. }\
  137. .col{\
  138. border:none;\
  139. }\
  140. .deletThis{\
  141. float:right;\
  142. cursor:pointer;\
  143. margin-right:10px;\
  144. padding:0 5px;\
  145. border:0;\
  146. height:18px;\
  147. }\
  148. .disable-btn{\
  149. background:#6B6B6B;\
  150. cursor:not-allowed;\
  151. }\
  152. #addBlackList input{\
  153. width:80%;\
  154. }\
  155. /*userName列表*/\
  156. #thread_list>li[data-field] .threadlist_lz>.threadlist_author,.l_post .d_name{\
  157. background:#303030;\
  158. cursor:pointer;\
  159. }\
  160. #sear{\
  161. position:relative;\
  162. margin:0 auto;\
  163. text-align:center;\
  164. height:21px;\
  165. width:100%;\
  166. border:none;\
  167. }\
  168. .confirm-div{\
  169. width:100%;\
  170. height:0;\
  171. text-align:center;\
  172. background:#303030;\
  173. overflow:hidden;\
  174. }\
  175. .confirm-div input{\
  176. margin:10px 5px;\
  177. padding:4px 10px;\
  178. border:none;\
  179. cursor:pointer;\
  180. }\
  181. .confirm-div p{\
  182. color:#37A69E;\
  183. letter-spacing:10px;\
  184. }\
  185. ';
  186. GM_addStyle(style);
  187. //============公共函数区==========
  188. function hasClass(obj,cName) {
  189. // ( \\s|^ ) 判断前面是否有空格 (\\s | $ )判断后面是否有空格 两个感叹号为转换为布尔值 以方便做判断
  190. return !! obj.className.match(new RegExp("(\\s|^)" + cName + "(\\s|$)"));
  191. };
  192. function addClass(obj, cName) {
  193. if (!hasClass(obj, cName)) {
  194. obj.className += " " + cName;
  195. };
  196. };
  197. function removeClass(obj, cName) {
  198. if (hasClass(obj, cName)) {
  199. obj.className = obj.className.replace(new RegExp("(\\s|^)" + cName + "(\\s|$)"), " "); // replace方法是替换
  200. };
  201. };
  202. function addEvent(obj, event, fn) {
  203. return obj.addEventListener ? obj.addEventListener(event, fn, false) : obj.attachEventListener('on' + event, fn);
  204. };
  205. function getStyle(obj, attr) {
  206. return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj)[attr];
  207. };
  208. function $(id) {
  209. return document.getElementById(id)
  210. };
  211. function getSize(attr){
  212. return document.documentElement[attr] ? document.documentElement[attr] : document.body[attr]
  213. }
  214. function insertAfter(newElement, targetElement) {
  215. var parent = targetElement.parentNode;
  216. if (parent.lastChild == targetElement) {
  217. parent.appendChild(newElement);
  218. } else {
  219. parent.insertBefore(newElement, targetElement.nextSibling);
  220. }
  221. }
  222. function doMove(obj, attr, dir, target, endFn) {
  223. dir = parseInt(getStyle(obj, attr)) < target ? dir: -dir; //对于方向矫正
  224. clearInterval(obj.timerMove) //清楚定时器
  225. obj.timerMove = setInterval(function() {
  226. var speed = parseInt(getStyle(obj, attr)) + dir //步长
  227. if (speed > target && dir > 0 || speed < target && dir < 0) { //判断往前或往后
  228. speed = target;
  229. };
  230. obj.style[attr] = speed + "px" //赋值
  231. if (speed == target) {
  232. clearInterval(obj.timerMove);
  233. endFn && endFn(); //回掉函数
  234. };
  235. },
  236. 30)
  237. };
  238. function uniqueArray(data){
  239. data = data || [];
  240. var a = {};
  241. for (var i=0; i<data.length; i++) {
  242. var v = data[i];
  243. if (typeof(a[v]) == 'undefined'){
  244. a[v] = 1;
  245. }
  246. };
  247. data.length=0;
  248. for (var i in a){
  249. data[data.length] = i;
  250. }
  251. return data;
  252. }
  253. //============主要代码区==========
  254. //判断当前url
  255. function juggUrl(){
  256. var url=location.href;
  257. var postIn=/.*tieba.baidu.com\/p\/.*/ig;
  258. var postList=/.*tieba.baidu.com\/(f\?.*|[^p])/ig;
  259. if( postIn.test(url) ){//如果是帖子内
  260. return 1;
  261. }else if( postList.test(url) ){//如果在帖子列表
  262. return 2;
  263. }
  264. }
  265. //生成屏蔽列表
  266. function createList(){
  267. $('showList').innerHTML='';
  268. var li='';
  269. for(var i=0;i<GM_listValues().length;i++){
  270. //控制台输出 键名:键值
  271. var key = GM_listValues()[i];
  272. var value = GM_getValue( GM_listValues()[i],'');
  273. if( (typeof value =='number' && value>1000) || value==''){
  274. //console.log( GM_listValues()[i] + ":" + GM_getValue(GM_listValues()[i],'') );
  275. li += '<li class="show_list" data="'+ key +'">'+'<span class="key">'+key+'</span>'+'<input class="deletThis" type="button" value="删除"/>'+'</li>';
  276. }//if
  277. }//for
  278. $('showList').innerHTML=li;
  279. var aDeleBtn=document.querySelectorAll('.deletThis');
  280. for(var i=0;i<aDeleBtn.length;i++){
  281. aDeleBtn[i].onclick=function(){
  282. var thisKey = this.parentNode.getAttribute('data');//获取当前结点的key
  283. GM_deleteValue( thisKey );//删除变量
  284. this.parentNode.remove( this.parentNode );//删除节点
  285. }//clickb
  286. }//for
  287. };
  288. //创建遮罩层
  289. function marks(obj){
  290. if(obj.querySelectorAll('.mar').length>=1){
  291. return;
  292. }
  293. var oMar = document.createElement('div');
  294. oMar.className = 'mar';
  295. //要屏蔽的模块
  296. obj.style.position = 'relative';
  297. obj.style.webkitFilter = 'blur('+ GM_getValue('setting-gus','3') +'px)';//chrome
  298. obj.style.filter = 'blur('+ GM_getValue('setting-gus','3') +'px)';//firefox
  299. obj.style.oFilter = 'blur('+ GM_getValue('setting-gus','3') +'px)';//opera
  300. obj.style.msFilter = 'blur('+ GM_getValue('setting-gus','3') +'px)';//IE
  301. obj.style.webkitBackfaceVisibility = 'hidden';
  302. obj.appendChild( oMar );
  303. //遮罩层
  304. oMar.style.width = parseInt( getStyle(obj,'width') ) + 'px';
  305. oMar.style.height = parseInt( getStyle(obj,'height') ) + 'px';
  306. oMar.style.background = GM_getValue('setting-col','#ffffff');
  307. oMar.style.opacity = GM_getValue('setting-opa','0.8');
  308. oMar.style.filter = 'alpha(opacity=' + GM_getValue('setting-opa','0.8')*100 +')';
  309. oMar.style.webkitBackfaceVisibility = 'hidden';
  310. };
  311. //判断屏蔽模式
  312. function blockMod(){
  313. if( GM_getValue('setting-blockWay','遮罩屏蔽')=='遮罩屏蔽' ){
  314. return 1;//遮罩模式
  315. }else{
  316. return 2;//删除节点
  317. }
  318. }
  319. //屏蔽确认
  320. var isBlock = false;//默认不屏蔽
  321. var expand = false; //记录是否展开
  322. var LastThis = null;//记录上一次点击
  323. function confirmBlock(This,list,n){
  324. if( LastThis == This && expand==true){//如果重复点击,并且已经显示屏蔽按钮
  325. doMove($('confirm-div'),'height',5,0,function(){
  326. $('confirm-div').remove(this);
  327. expand = false;
  328. })
  329. return;
  330. }
  331. LastThis = This;
  332. if( $('confirm-div') ){//如果页面上有按钮
  333. var allConfirmDiv = document.querySelectorAll('.confirm-div');
  334. //清空按钮
  335. for(var i=0;i<allConfirmDiv.length;i++){
  336. allConfirmDiv[i].remove(allConfirmDiv[i]);
  337. }//for
  338. }
  339. var confirmDiv = document.createElement('div');
  340. if( juggUrl()==1 ){
  341. insertAfter(confirmDiv,This);
  342. }else{
  343. insertAfter(confirmDiv,This.parentNode);
  344. }
  345. confirmDiv.className = 'confirm-div';
  346. confirmDiv.id = 'confirm-div';
  347. confirmDiv.innerHTML = '\
  348. <p>是否屏蔽</p>\
  349. <input id="confirm-yes" type="button" value="确认" \><input id="confirm-no" type="button" value="取消" \>\
  350. ';
  351. doMove(confirmDiv,'height',5,65,function(){
  352. expand = true;
  353. })//展开
  354. $('confirm-yes').onclick=function(){//确认
  355. isBlock = true;
  356. btclick(This,list,n);
  357. doMove(confirmDiv,'height',5,0,function(){
  358. confirmDiv.remove(this);
  359. expand = true;
  360. })
  361. }
  362. $('confirm-no').onclick=function(){//取消
  363. isBlock = false;
  364. doMove(confirmDiv,'height',5,0,function(){
  365. confirmDiv.remove(this);
  366. expand = false;
  367. })
  368. }
  369. }
  370. //点击屏蔽
  371. function btclick(This,list,n){
  372. var _thisTop,_thisUserId,_thisUserName,nowUserId,nowUserName;
  373. if(n=='postList'){
  374. _thisTop = This.parentNode.parentNode.parentNode.parentNode;
  375. _thisUserId = JSON.parse(_thisTop.getAttribute('data-field')).id;//当前id
  376. _thisUserName = JSON.parse(_thisTop.getAttribute('data-field')).author_name;//当前userName
  377. }else if(n=='post'){
  378. _thisTop = This.parentNode.parentNode.parentNode;
  379. _thisUserId = JSON.parse(_thisTop.getAttribute('data-field')).author.user_id;//当前id
  380. _thisUserName = JSON.parse(_thisTop.getAttribute('data-field')).author.user_name;//当前userName
  381. }
  382. //confirmBlock()
  383. //if ( confirm('是否屏蔽') == true) { //如果按下确认
  384. //confirmBlock();
  385. if ( isBlock == true) { //如果按下确认
  386. GM_setValue( _thisUserName,_thisUserId );
  387. for (var j = 0; j < list.length; j++) {//循环匹配是否符合
  388. var userInfo = JSON.parse(list[j].getAttribute('data-field'))
  389. if(n=='postList'){
  390. nowUserId = userInfo.id;
  391. nowUserName = userInfo.author_name;
  392. }else if(n=='post'){
  393. nowUserId = userInfo.author.user_id;
  394. nowUserName = userInfo.author.user_name;
  395. }
  396. if (nowUserId == _thisUserId || nowUserName==_thisUserName) {//匹配成功
  397. if( blockMod()==1 ){//遮罩模式
  398. marks(list[j]);
  399. }else{//删除节点模式
  400. list[j].style.display = 'none';
  401. }
  402. }//匹配是否符
  403. } //for
  404. }//if如果按下确认
  405. }
  406. //页面加载开始屏蔽
  407. function block(name,id,list,I){
  408. for(var j=0;j<GM_listValues().length;j++){
  409. if( GM_listValues()[j] == name || GM_getValue(GM_listValues()[j],'') == id ){//如果匹配到
  410. if( blockMod()==1 ){//遮罩模式
  411. marks(list[I]);
  412. }else{//删除节点模式
  413. list[I].style.display = 'none';
  414. }
  415. }//匹配是否符合
  416. }//for,遍历屏蔽
  417. }
  418. //控制面板userName智能提示
  419. function autoTips(){
  420. var aUsers,userName,userId;
  421. if( juggUrl()==1 ){//帖子内
  422. var aTipsArr = new Array();
  423. var newString = '';
  424. aUsers = document.querySelectorAll('#j_p_postlist>div[data-field]');//获取列表
  425. for(var i=0;i<aUsers.length;i++){
  426. userName = JSON.parse(aUsers[i].getAttribute('data-field')).author.user_name;//第i个userName
  427. userId = JSON.parse(aUsers[i].getAttribute('data-field')).author.user_id;//第i个userId
  428. aTipsArr.push( userName );
  429. }
  430. uniqueArray( aTipsArr );
  431. for(var i=0;i<aTipsArr.length;i++){
  432. newString += '<option value="' + aTipsArr[i] + '" />';
  433. }
  434. lst.innerHTML = newString;
  435. }else{//帖子列表
  436. var aTipsArr = new Array();
  437. var newString = '';
  438. aUsers=document.querySelectorAll('#thread_list>li[data-field]');//获取列表
  439. for(var i=0;i<aUsers.length;i++){
  440. userName = JSON.parse(aUsers[i].getAttribute('data-field')).author_name;//第i个userName
  441. userId = JSON.parse(aUsers[i].getAttribute('data-field')).id;//第i个userId
  442. aTipsArr.push( userName );
  443. }
  444. uniqueArray( aTipsArr );
  445. for(var i=0;i<aTipsArr.length;i++){
  446. newString += '<option value="' + aTipsArr[i] + '" />';
  447. }
  448. lst.innerHTML = newString;
  449. }//if....else
  450. }
  451. //关闭控制面板
  452. function closePannal(){
  453. doMove($('list'),'height',40,20,function(){
  454. doMove($('list'),'width',25,0,function(){//收起
  455. $('view').value = '>>';
  456. turn = false;
  457. $('pannal-troy').style.overflow = 'hidden';
  458. doMove($('pannal-troy'),'height',40,15,function(){
  459. doMove($('pannal-troy'),'width',25,0,function(){
  460. $('pannal-troy').remove(this);
  461. $('mars').remove(this);
  462. document.body.className = '';
  463. })
  464. })
  465. });
  466. })
  467. }
  468. //初始化程序
  469. function init() {
  470. //=======帖子内==========
  471. if( juggUrl()==1 ){
  472. var aShut = document.querySelector('.l_post .d_name');
  473. if( aShut.onclick ){
  474. return false;
  475. }
  476. var aUsers = document.querySelectorAll('#j_p_postlist>div[data-field]');//获取列表
  477. var aName = document.querySelectorAll('.l_post .d_name');//屏蔽按钮将要插入的位置
  478. for (var i = 0; i < aUsers.length; i++) {
  479. //获取id和name
  480. var userName = JSON.parse(aUsers[i].getAttribute('data-field')).author.user_name;//第i个userName
  481. var userId = JSON.parse(aUsers[i].getAttribute('data-field')).author.user_id;//第i个userId
  482. //添加点击事件
  483. aName[i].onclick=function(){
  484. var this_=this;
  485. //btclick(this_,aUsers,'post','author[user_id]','author[user_name]');
  486. confirmBlock(this_,aUsers,'post','author[user_id]','author[user_name]');
  487. }
  488. //页面加载开始屏蔽
  489. block(userName,userId,aUsers,i);
  490. } //for,遍历所有节点
  491. //=======帖子列表==========
  492. }else if( juggUrl()==2 ){
  493. var aShut = document.querySelector('#thread_list>li[data-field] .threadlist_lz>.threadlist_author, .l_post .d_name');
  494. if( aShut.onclick ){
  495. return false;
  496. }
  497. var aUsers=document.querySelectorAll('#thread_list>li[data-field]');//获取列表
  498. var aName = document.querySelectorAll('#thread_list>li[data-field] .threadlist_lz>.threadlist_author');//屏蔽按钮将要插入的位置
  499. for(var i=0;i<aUsers.length;i++){
  500. //获取id和name
  501. var userName = JSON.parse(aUsers[i].getAttribute('data-field')).author_name;//第i个userName
  502. var userId = JSON.parse(aUsers[i].getAttribute('data-field')).id;//第i个userId
  503. //添加点击事件
  504. aName[i].onclick=function(){
  505. var this_=this;
  506. //btclick(this_,aUsers,'postList','id','author_name');
  507. confirmBlock(this_,aUsers,'postList','id','author_name');
  508. }
  509. //页面加载开始屏蔽
  510. block(userName,userId,aUsers,i)
  511. }//for,遍历所有节点
  512. }//在帖子列表
  513. }//初始化
  514. //============执行区==========
  515. addEvent(window,'load',function(){
  516. init();
  517. })
  518. //跟随翻页加载
  519. var aUsers,aShut;
  520. addEvent(window,'scroll',function(){
  521. if( getSize('scrollTop') == 0){
  522. clearTimeout(document.TPage);
  523. document.TPage = setTimeout(init,3000);
  524. }//如果滚动到顶部
  525. })
  526. //阻止事件冒泡
  527. addEvent(document,'click',function(e){
  528. var e = e || window.event;
  529. var target = e.target || e.srcElement;
  530. //if( 如果在帖子内 || 如果在帖子列表 )
  531. if( target.getAttribute('data-field') && hasClass(target.parentNode,'d_name') || target.getAttribute('data-field') && hasClass(target.parentNode,'threadlist_author') ){//如果点到了名字上面
  532. if(e && e.stopPropagation){//chrome,firefox
  533. e.preventDefault();//阻止默认事件
  534. e.stopPropagation();//阻止冒泡
  535. }else{//ie
  536. e.returnValue = false;//阻止默认事件
  537. e.cancelBubble = true;//阻止冒泡
  538. }
  539. }//如果匹配
  540. //收起屏蔽按钮
  541. if( expand == true && $('confirm-div')){
  542. clearTimeout(document.autoHideBlockBtn);
  543. document.autoHideBlockBtn = setTimeout(function(){
  544. doMove($('confirm-div'),'height',5,0,function(){
  545. $('confirm-div').remove(this);
  546. expand = false;
  547. })
  548. },3000)
  549. }
  550. })
  551. //============控制面板以及相关==========
  552. addEvent(window,'resize',function(){
  553. if( $('pannal-troy') ){
  554. $('pannal-troy').style.top = ( getSize('clientHeight') - $('pannal-troy').offsetHeight )/2 + 'px';
  555. $('pannal-troy').style.left = ( getSize('clientWidth') - $('pannal-troy').offsetWidth )/2 + 'px';
  556. }
  557. })
  558. addEvent(window,'keyup',function(e){
  559. var e = e || window.event;
  560. if( e.ctrlKey && e.keyCode==114 ){//快捷键ctrl+F3
  561. if( $('pannal-troy') ) return;
  562. var pannal = document.createElement('div');
  563. var pannal_mars = document.createElement('div');
  564. pannal_mars.id = 'mars';
  565. pannal.id = 'pannal-troy';
  566. pannal.innerHTML='\
  567. <h3>配置参数</h3>\
  568. <div id="pannal-setting">\
  569. 屏蔽方式:<select id="blockWay">\
  570. <option>遮罩屏蔽</option>\
  571. <option>删除节点</option>\
  572. </select><br/>\
  573. 遮罩层颜色:<input id="col" type="color" /><br/>\
  574. 遮罩透明度(0~1):<span id="opa-text"></span><input id="opa" type="range" min="0" max="1" step="0.1" /><br/>\
  575. 高斯模糊像素(0~10):<span id="gus-text"></span><input id="gus" type="range" min="0" max="10" step="1" /><br/>\
  576. </div>\
  577. <hr/>\
  578. <h3>添加讨厌鬼</h3>\
  579. <div id="addBlackList">\
  580. 数字ID(选填):<input id="userId" type="text" placeholder="user_id"/><br/>\
  581. 贴吧ID(必填):<input id="userName" type="text" placeholder="user_name" list="lst" autocomplete="off"/>\
  582. <datalist id="lst" autocomplete="on"></datalist>\
  583. </div>\
  584. <hr/>\
  585. <h3>功能</h3>\
  586. <div id="fn">\
  587. <input id="save" type="button" value="保存" />\
  588. <input id="clear" type="button" value="清空" />\
  589. <input id="view" type="button" value=">>" />\
  590. </div>\
  591. <div id="list">\
  592. <input id="sear" type="text" list="BlackList" placeholder="搜索" autocomplete="off" />\
  593. <ul id="showList"></ul>\
  594. </div>\
  595. <span id="queit">X</span>\
  596. '
  597. document.documentElement.appendChild( pannal );
  598. document.documentElement.appendChild( pannal_mars );
  599. document.body.className = 'blur';
  600. pannal.style.top = ( getSize('clientHeight') - pannal.offsetHeight )/2 + 'px';
  601. pannal.style.left = ( getSize('clientWidth') - pannal.offsetWidth )/2 + 'px';
  602. //初始化
  603. $('blockWay').value = GM_getValue('setting-blockWay','遮罩屏蔽' );//屏蔽方式
  604. $('col').value = GM_getValue('setting-col','#ffffff'); //默认遮罩的颜色
  605. $('opa').value = GM_getValue('setting-opa','0.8'); //默认遮罩透明度
  606. $('opa-text').innerHTML = $('opa').value;
  607. $('gus').value = GM_getValue('setting-gus','3'); //默认遮罩下的高斯模糊半径
  608. $('gus-text').innerHTML = $('gus').value;
  609. createList(); //加载黑名单列表
  610. addEvent($('opa'),'input',function(){
  611. $('opa-text').innerHTML = $('opa').value;
  612. })
  613. addEvent($('gus'),'input',function(){
  614. $('gus-text').innerHTML = $('gus').value;
  615. })
  616. //智能提示userName和userId
  617. addEvent($('userName'),'input',function(){
  618. autoTips();
  619. })
  620. //删除节点模式则禁用选项
  621. addEvent($('blockWay'),'input',function(){
  622. var aInput=[$('col'),$('opa'),$('gus')]
  623. if( $('blockWay').value == '删除节点' ){//删除节点模式
  624. for(var i=0;i<aInput.length;i++){
  625. aInput[i].readOnly = 'true';
  626. aInput[i].className = 'disable-btn';
  627. }
  628. }else{//遮罩屏蔽模式模式
  629. for(var i=0;i<aInput.length;i++){
  630. aInput[i].readOnly = 'false';
  631. aInput[i].className = '';
  632. }
  633. }
  634. })
  635. //====保存按钮====
  636. addEvent($('save'),'click',function(){
  637. //判断屏蔽方式
  638. if($('blockWay').value=='遮罩屏蔽'){
  639. GM_setValue('setting-blockWay','遮罩屏蔽');
  640. }else if($('blockWay').value=='删除节点'){
  641. GM_setValue('setting-blockWay','删除节点');
  642. }
  643. //遮罩颜色
  644. GM_setValue('setting-col',$('col').value);
  645. //遮罩透明度1
  646. GM_setValue('setting-opa',$('opa').value);
  647. //高斯模糊半径
  648. GM_setValue('setting-gus',$('gus').value);
  649. //匹配ID是否正确
  650. var regId=/^[1-9][0-9]{4,}$/ig;
  651. if( $('userName').value!='' && (regId.test($('userId').value)==true || $('userId').value=='') ){
  652. //保存形式:user_name:user_id
  653. GM_setValue( $('userName').value,$('userId').value );
  654. alert('保存成功' + "\n用户名:" + $('userName').value + "\nID:" + GM_getValue($('userName').value,'') + '\n屏蔽方式:'+ GM_getValue('setting-blockWay','遮罩屏蔽' )+'\n遮罩颜色:' + GM_getValue('setting-col','#fff') + '\n遮罩透明度:'+ GM_getValue('setting-opa','0.8') +'\n高斯模糊:'+GM_getValue('setting-gus','3') );
  655. }else if( $('userName').value=='' && $('userId').value==''){
  656. alert('保存成功\n屏蔽方式:'+ GM_getValue('setting-blockWay','遮罩屏蔽' )+'\n遮罩颜色:' + GM_getValue('setting-col','#fff') + '\n遮罩透明度:'+ GM_getValue('setting-opa','0.8') +'\n高斯模糊:'+GM_getValue('setting-gus','3') )
  657. }else{
  658. alert('输入不正确:\n数字ID:选填([5~n位数])\n贴吧ID:必填')
  659. }
  660. if( parseInt( getStyle($('list'),'width') )>0 ){//如果列表已经展开
  661. createList()//重新生成列表
  662. }
  663. })
  664. //====清空按钮====
  665. addEvent($('clear'),'click',function(){
  666. for(var i=0;i<GM_listValues().length;i++){
  667. //清空所有变量
  668. //GM_deleteValue( GM_listValues()[i] ) + ":" + GM_getValue( GM_listValues()[i],'' )
  669. var value = GM_getValue( GM_listValues()[i],'');
  670. if( (typeof value=='number' && value>1000) || value==''){
  671. GM_deleteValue( GM_listValues()[i] );//删除键名
  672. }
  673. }//for
  674. if( parseInt(getStyle($('list'),'width'))>0 ){//如果列表已经展开
  675. createList();//重新生成列表
  676. }
  677. })
  678. //====展开/收起按钮====
  679. var turn = false;
  680. addEvent($('view'),'click',function(){
  681. if(turn == false){
  682. createList();
  683. //$('showList').style.overflowY = 'scroll';
  684. doMove($('list'),'width',20,200,function(){//展开
  685. doMove($('list'),'height',40,321,function(){
  686. $('sear').focus();
  687. $('view').value = '<<';
  688. turn = true;
  689. });
  690. })
  691. }else if( turn == true ){
  692. //$('showList').style.overflowY = 'hidden';
  693. doMove($('list'),'height',40,20,function(){
  694. doMove($('list'),'width',20,0,function(){//收起
  695. $('view').value = '>>';
  696. turn = false;
  697. });
  698. })
  699. }
  700. })
  701. //黑名单搜索
  702. addEvent($('sear'),'input',function(){
  703. createList();
  704. var list = document.querySelectorAll('#showList .show_list');
  705. $('showList').innerHTML = '';//清空列表
  706. var str = '';
  707. for(var i=0;i<list.length;i++){
  708. var userName = list[i].getAttribute('data');
  709. if( userName.indexOf( $('sear').value ) >=0 ){//如果搜索到
  710. str += '<li class="show_list" data="'+ userName +'">'+'<span class="key">'+userName+'</span>'+'<input class="deletThis" type="button" value="删除"/>'+'</li>';
  711. }
  712. }//for
  713. $('showList').innerHTML = str;//生成列表
  714. //添加点击事件
  715. var aDeleBtn=document.querySelectorAll('.deletThis');
  716. for(var i=0;i<aDeleBtn.length;i++){
  717. aDeleBtn[i].onclick=function(){
  718. var thisKey = this.parentNode.getAttribute('data');//获取当前结点的key
  719. GM_deleteValue( thisKey );//删除变量
  720. this.parentNode.remove( this.parentNode );//删除节点
  721. }//click
  722. }//for
  723. })
  724. //黑名单搜索,backspace键
  725. addEvent(window,'keyup',function(e){
  726. var e= e || window.event;
  727. if(e.keyCode==8){//backspace
  728. if( $('sear').value == '' ){
  729. createList();
  730. }
  731. }
  732. })
  733. //===关闭按钮====
  734. addEvent($('queit'),'click',function(){
  735. closePannal();
  736. })
  737. addEvent($('mars'),'click',function(){
  738. closePannal();
  739. })
  740. }//if
  741. })//addEvent

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址