nmbhs

hide sage threads

  1. // ==UserScript==
  2. // @name nmbhs
  3. // @namespace fishcan
  4. // @description hide sage threads
  5. // @include https://h.nimingban.com/*
  6. // @version 1.1
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10.  
  11. var sageThreads = [];
  12. var sageIndex = [];
  13.  
  14. var sageIcon = document.getElementsByClassName("uk-icon-thumbs-down");
  15. // 由于js的动态性,如果dom中节点消失了,那么其对应的集合也会消失;
  16. //(其实这是我瞎编的,但是一下代码的效果上来说就是这样)
  17. while(sageIcon.length > 0){
  18. var thisNode = sageIcon[0].parentNode.parentNode;
  19. var thisId = thisNode.getAttribute("data-threads-id");
  20. if(thisId == null){
  21. // 针对红名的标了sage的置顶串,其实其内部的结构和一般的sage并不一样
  22. sageIcon[0].setAttribute("class","uk-icon-plus-square");
  23. continue;
  24. }
  25. var cNode = document.createElement("div");
  26. cNode.setAttribute("class","h-threads-item uk-clearfix");
  27. var node = document.createElement("span");
  28. var blank = document.createElement("span");
  29. node.setAttribute("class","h-threads-info-reply-btn uk-text-danger uk-text-bold");
  30. node.innerHTML = "[<a style='color:#d85030'>==sage==</a>]";
  31. node.firstElementChild.setAttribute("id",thisId);
  32. cNode.appendChild(node);
  33. sageThreads.push(thisNode.cloneNode(true));
  34. sageIndex.push(thisId);
  35. thisNode.parentNode.replaceChild(cNode,thisNode);
  36. document.getElementById(thisId).addEventListener('click', toggleHideSage, true);
  37. }
  38.  
  39. function toggleHideSage(e){
  40. var thisThreads = this.parentNode.parentNode
  41. e.stopPropagation();
  42. var index = sageIndex.indexOf(this.getAttribute("id"));
  43. if(thisThreads.firstElementChild.nextElementSibling == null){
  44. thisThreads.appendChild(sageThreads[index]);
  45. }else{
  46. thisThreads.removeChild(thisThreads.firstElementChild.nextElementSibling);
  47. }
  48. }