remove the posts which make you sick

移除讨厌鬼的帖子

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

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

QingJ © 2025

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