remove the posts which make you sick

移除讨厌鬼的帖子

当前为 2015-07-09 提交的版本,查看 最新版本

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

QingJ © 2025

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