Greasy Fork

来自缓存

Greasy Fork is available in English.

屏蔽游民引战狗

引战狗滚出游民

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         屏蔽游民引战狗
// @namespace    http://tampermonkey.net/
// @version      0.12
// @description  引战狗滚出游民
// @author       cinemachine
// @match        www.gamersky.com/news/*
// @icon         https://www.google.com/s2/favicons?domain=gamersky.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //要屏蔽用户的ID写在这里
    const banID = ["4769237","3374855"];
    // Your code here...
    var node = document.querySelector(".cmt_list_cont");

    var config = { attributes: false, childList: true, subtree: true };

    // 当观察到突变时执行的回调函数
    var callback = function(mutationsList) {


        mutationsList.forEach(function(item,index){
            //console.log(item.addedNodes);
            if (item.type == 'childList')
            {
                for(var i = item.addedNodes.length - 1; i >= 0; i-- )
                {
                   if(item.addedNodes[i].className === "cmt_cont")
                   {
                       var name = item.addedNodes[i].querySelector(".uname");
                       if(name != null)
                       {
                           var id = name.getAttribute("uid");
                           if(banID.indexOf(id) != -1)
                           {
                               item.addedNodes[i].remove(i);
                               continue;
                           }
                           var reply = item.addedNodes[i].querySelector(".cmt_list");
                           if(reply != null)
                           {
                               for(var j = reply.childNodes.length - 1; j >= 0; j--)
                               {
                                   var rname = reply.childNodes[j].querySelector(".uname");
                                   var rid = rname.getAttribute("uid");
                                   if(banID.indexOf(rid) != -1)
                                   {
                                       reply.childNodes[j].remove(j);
                                   }
                               }
                           }
                       }
                   }
                   else if(item.addedNodes[i].className === "cmt_reply_con")
                   {
                       var u = item.addedNodes[i].querySelector(".userlink");
                       var uid = u.getAttribute("uid");
                       if(banID.indexOf(uid) != -1)
                       {
                            item.addedNodes[i].remove(i);
                       }


                   }
                }
            }
        });
    };

    // 创建一个链接到回调函数的观察者实例
    var observer = new MutationObserver(callback);

    // 开始观察已配置突变的目标节点
    observer.observe(node, config);


})();