nmbb

nimingban threads block

当前为 2016-10-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name nmbb
  3. // @namespace fishcan
  4. // @description nimingban threads block
  5. // @include https://h.nimingban.com/*
  6. // @version 1
  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.  
  21. var allThreads = document.getElementsByClassName("h-threads-item");
  22. for(var i = 0; i < allThreads.length; i++){
  23. var node = document.createElement("span");
  24. node.setAttribute("class","h-threads-info-report-btn");
  25. var nodeA = document.createElement("a");
  26. nodeA.setAttribute("id",allThreads[i].getAttribute("data-threads-id"));
  27. var textnode = document.createTextNode("屏蔽");
  28. var tp = document.createTextNode("[");
  29. var ta = document.createTextNode("]");
  30. nodeA.appendChild(textnode);
  31. node.appendChild(tp);
  32. node.appendChild(nodeA);
  33. node.appendChild(ta);
  34. allThreads[i].firstElementChild.firstElementChild.appendChild(node);
  35. document.getElementById(allThreads[i].getAttribute("data-threads-id")).addEventListener('click', addblock, true);
  36. }
  37.  
  38. function removeThreads(){
  39. for(var i = 0; i < allThreads.length; i++){
  40. var thisId = allThreads[i].getAttribute("data-threads-id");
  41. var thisNode = allThreads[i];
  42. var thisIndex = blist.indexOf(thisId)
  43. if(thisIndex>-1){
  44. // 移除串内容改为替换为撤销按钮
  45. while(thisNode.hasChildNodes()){
  46. thisNode.removeChild(thisNode.lastChild)
  47. }
  48. var node = document.createElement("span");
  49. node.setAttribute("class","h-threads-info-reply-btn");
  50. node.innerHTML = "[<a>撤销屏蔽</a>]";
  51. node.firstElementChild.setAttribute("id",thisId);
  52. thisNode.appendChild(node)
  53. document.getElementById(thisId).addEventListener('click', cancelBlock, true)
  54. // 将被使用到的规则移到前面
  55. blist.splice(thisIndex,1);
  56. blist.unshift(thisId);
  57. }
  58. }
  59. GM_setValue('blist',blist)
  60. }
  61.  
  62. function addblock(e){
  63. e.stopPropagation();
  64. var thisId=this.getAttribute("id");
  65. blist.push(thisId);
  66. GM_setValue('blist',blist)
  67. removeThreads();
  68. }
  69.  
  70. function cancelBlock(e){
  71. e.stopPropagation();
  72. var thisId = this.getAttribute("id");
  73. var thisIndex = blist.indexOf(thisId);
  74. if(thisIndex>-1){
  75. blist.splice(thisIndex,1)
  76. GM_setValue('blist',blist)
  77. }
  78. location.reload();
  79. }
  80.  
  81. removeThreads()