用户成分指示器(修改自原神玩家指示器)

B站视频评论区自动标注动态里有转发原神、王者荣耀、明日方舟、肖战抽奖的用户,可自行修改。原脚本作者xulaupuz

当前为 2022-09-11 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         用户成分指示器(修改自原神玩家指示器)
// @namespace    CoolBreeze.Ingredient.Indicator
// @version      0.1.0
// @description  B站视频评论区自动标注动态里有转发原神、王者荣耀、明日方舟、肖战抽奖的用户,可自行修改。原脚本作者xulaupuz
// @author       CoolBreeze
// @match        https://www.bilibili.com/video/*
// @icon         https://static.hdslb.com/images/favicon.ico
// @grant        GM_xmlhttpRequest
// @license MIT
// @run-at document-end
// ==/UserScript==

(function () {
  'use strict';

  const KEYWORDS = ['原神', '王者荣耀', '明日方舟', '肖战'];//要检测的关键词
  const CONTEMPT = ['原批', '农批', '粥批', '虾爬子'];//对这类有关键词用户的蔑称
  //上面两行可以根据情况自行增加删除。

  if (KEYWORDS.length != CONTEMPT.length) {
    console.error('keywords与contempt的长度不一致!');//要保证关键词与蔑称都有对应,长度不一样就报错
    return;
  }

  const CheckKeywords = setInterval(() => {
    let isOldVersion = false;

    //检测是否为旧版
    if ((document.getElementsByClassName('item goback')).length == 0) {
      isOldVersion = true;
    }

    //枚举评论区的回复
    let commentlist = document.getElementsByClassName('user' + (isOldVersion ? '' : '-name'));

    //如果评论区有回复则执行代码
    if (commentlist.length > 0) {
      //清除上一次的定时器
      clearInterval(CheckKeywords);
      commentlist.forEach(commentUserName => {
        let pid = isOldVersion ? commentUserName.children[0].href.replace(/[^\d]/g, "") : commentUserName.dataset.userId;
        let blogurl = `https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?&host_mid=${pid}`
        GM_xmlhttpRequest({
          method: "get",
          url: blogurl,
          data: '',
          headers: {
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
          },
          onload: function (res) {
            if (res.status === 200) {
              let tag = [];
              for (const item of JSON.parse(res.response).data.items) {
                try {
                  let richTextNodes = item.orig.modules.module_dynamic.desc.rich_text_nodes;//获取动态来源的文本
                  richTextNodes.forEach(node => {//遍历动态文本节点
                    let i = 0;
                    KEYWORDS.forEach(keyword => {//遍历关键词
                      if (!tag.includes(CONTEMPT[i]) && node.orig_text.includes(keyword) && (node.orig_text.includes('抽奖') || node.orig_text.includes('转发'))) {
                        tag.push(CONTEMPT[i++]);//如果tag里面还没有并且检测到了关键词就加进去
                      }
                    });
                  });
                }
                catch (err) {
                  continue;//脱了裤子放屁。。但是空一行不好看我就写上了
                }
              }
              if (tag.length > 0) {
                let userNameElement = document.createElement("span");
                userNameElement.innerHTML = `<span style='background-color:#F03;padding:3px;border-radius:5px;color:white;font-weight:bold'>警告:${tag}</span>`;
                commentUserName.appendChild(userNameElement);
              }
            }
          },
        });
      });
    }
  }, 2000)
})();