nmbb

nimingban threads block

  1. // ==UserScript==
  2. // @name nmbb
  3. // @namespace fishcan
  4. // @description nimingban threads block
  5. // @include https://h.nimingban.com/*
  6. // @version 1.2
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // ==/UserScript==
  10.  
  11. var blist = [];
  12. blist = GM_getValue('blist',[]);
  13.  
  14. /************************
  15. *截断超过长度的屏蔽列表
  16. *************************/
  17. if(blist.length>100){
  18. blist=blist.slice(0,100);
  19. }
  20. var allThreads = document.getElementsByClassName("h-threads-item");
  21.  
  22. for(var i = 0; i < allThreads.length; i++){
  23. var thisId = allThreads[i].getAttribute("data-threads-id");
  24. var thisNode = allThreads[i];
  25. var node = document.createElement("span");
  26. node.setAttribute("class","h-threads-info-report-btn");
  27. node.innerHTML = "[<a>屏蔽串</a>]";
  28. node.firstElementChild.setAttribute("id",thisId);
  29. var now = thisNode.firstElementChild.firstElementChild
  30. while(now != null){
  31. if(now.className == "h-threads-info"){
  32. now.appendChild(node);
  33. break;
  34. }else{now = now.nextElementSibling;}
  35. }
  36. document.getElementById(thisId).addEventListener('click', addBlock, true);
  37. }
  38.  
  39. function removeThreads(){
  40. for(var i = 0; i < allThreads.length; i++){
  41. var thisId = allThreads[i].getAttribute("data-threads-id");
  42. var thisNode = allThreads[i];
  43. var thisIndex = blist.indexOf(thisId)
  44. if(thisIndex>-1){
  45. // 移除串内容改为替换为撤销按钮
  46. while(thisNode.hasChildNodes()){
  47. thisNode.removeChild(thisNode.lastChild)
  48. }
  49. var node = document.createElement("span");
  50. node.setAttribute("class","h-threads-info-reply-btn");
  51. node.innerHTML = "[<a>撤销屏蔽</a>]";
  52. node.firstElementChild.setAttribute("id",thisId);
  53. thisNode.appendChild(node)
  54. document.getElementById(thisId).addEventListener('click', cancelBlock, true)
  55. // 将被使用到的规则移到前面
  56. blist.splice(thisIndex,1);
  57. blist.unshift(thisId);
  58. }
  59. }
  60. GM_setValue('blist',blist)
  61. }
  62.  
  63. function addBlock(e){
  64. e.stopPropagation();
  65. var thisId=this.getAttribute("id");
  66. blist.push(thisId);
  67. GM_setValue('blist',blist)
  68. removeThreads();
  69. }
  70.  
  71. function cancelBlock(e){
  72. e.stopPropagation();
  73. var thisId = this.getAttribute("id");
  74. var thisIndex = blist.indexOf(thisId);
  75. if(thisIndex>-1){
  76. blist.splice(thisIndex,1)
  77. GM_setValue('blist',blist)
  78. }
  79. location.reload();
  80. }
  81.  
  82. removeThreads()