nmbhs

hide sage threads

目前為 2016-10-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        nmbhs
// @namespace   fishcan
// @description hide sage threads
// @include     https://h.nimingban.com/*
// @version     1.1
// @grant       none
// ==/UserScript==


var sageThreads = [];
var sageIndex = [];

var sageIcon = document.getElementsByClassName("uk-icon-thumbs-down");
// 由于js的动态性,如果dom中节点消失了,那么其对应的集合也会消失;
//(其实这是我瞎编的,但是一下代码的效果上来说就是这样)
while(sageIcon.length > 0){
  var thisNode = sageIcon[0].parentNode.parentNode;
  var thisId = thisNode.getAttribute("data-threads-id");
  if(thisId == null){
    // 针对红名的标了sage的置顶串,其实其内部的结构和一般的sage并不一样
    sageIcon[0].setAttribute("class","uk-icon-plus-square");
    continue;
  }
  var cNode = document.createElement("div");
  cNode.setAttribute("class","h-threads-item uk-clearfix");
  var node = document.createElement("span");
  var blank = document.createElement("span");
  node.setAttribute("class","h-threads-info-reply-btn uk-text-danger uk-text-bold");
  node.innerHTML = "[<a style='color:#d85030'>==sage==</a>]";
  node.firstElementChild.setAttribute("id",thisId);
  cNode.appendChild(node);
  sageThreads.push(thisNode.cloneNode(true));
  sageIndex.push(thisId);
  thisNode.parentNode.replaceChild(cNode,thisNode);
  document.getElementById(thisId).addEventListener('click', toggleHideSage, true);
}

function toggleHideSage(e){
  var thisThreads = this.parentNode.parentNode
  e.stopPropagation();
  var index = sageIndex.indexOf(this.getAttribute("id"));
  if(thisThreads.firstElementChild.nextElementSibling == null){
    thisThreads.appendChild(sageThreads[index]);
  }else{
    thisThreads.removeChild(thisThreads.firstElementChild.nextElementSibling);
  }
}