const get_comment_list = () => { if (is_new) { let lst = new Set() for (let c of document.getElementsByClassName('user-name')) { lst.add(c) } for (let c of document.getElementsByClassName('sub-user-name')) { lst.add(c) } return lst } else { return document.getElementsByClassName('user') } }
console.log(is_new)
console.log("正常加载") let jiance = setInterval(() => { let commentlist = get_comment_list() if (commentlist.length != 0) { // clearInterval(jiance) commentlist.forEach(c => { let pid = get_pid(c) if (done.has(pid)) { if (yuanyou.has(pid) && c.textContent.includes(tag1) === false) { c.append(tag1) } if (zhouyou.has(pid) && c.textContent.includes(tag2) === false) { c.append(tag2) } if (nongyou.has(pid) && c.textContent.includes(tag3) === false) { c.append(tag3) } return }
//console.log(pid) let blogurl = blog + pid // let xhr = new XMLHttpRequest() 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) { done.add(pid) //console.log('成功') let st = JSON.stringify(JSON.parse(res.response).data) if (st.includes(keyword1) && !yuanyou.has(pid)) { c.append(tag1) yuanyou.add(pid) } if (st.includes(keyword2) && !zhouyou.has(pid)) { c.append(tag2) zhouyou.add(pid) } if (st.includes(keyword3) && !nongyou.has(pid)) { c.append(tag3) nongyou.add(pid) } } else { done.add(pid) console.log('失败') console.log(res) } }, }); }); } }, 4000) })();
自用版,集合三种伟力:【原神】【明日方舟】【王者荣耀】
// ==UserScript==
// @name 玩家指示器
// @namespace www.cber.ltd
// @version 0.6
// @description B站评论区自动标注原神玩家,依据是动态里是否有原神相关内容(0.6一些小的修改)
// @author xulaupuz
// @match https://www.bilibili.com/video/*
// @icon https://static.hdslb.com/images/favicon.ico
// @connect bilibili.com
// @grant GM_xmlhttpRequest
// @license MIT
// @run-at document-end
// ==/UserScript==
(function () {
'use strict';
const yuanyou = new Set()
const zhouyou = new Set()
const nongyou = new Set()
const done = new Set()
const keyword1 = "原神"
const keyword2 = "明日方舟"
const keyword3 = "王者荣耀"
const tag1 = "【原友】"
const tag2 = "【舟友】"
const tag3 = "【农友】"
const blog = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?&host_mid='
const is_new = document.getElementsByClassName('item goback').length != 0 // 检测是不是新版
const get_pid = (c) => {
if (is_new) {
return c.dataset['userId']
} else {
return c.children[0]['href'].replace(/[^\d]/g, "")
}
}
const get_comment_list = () => {
if (is_new) {
let lst = new Set()
for (let c of document.getElementsByClassName('user-name')) {
lst.add(c)
}
for (let c of document.getElementsByClassName('sub-user-name')) {
lst.add(c)
}
return lst
} else {
return document.getElementsByClassName('user')
}
}
console.log(is_new)
console.log("正常加载")
let jiance = setInterval(() => {
let commentlist = get_comment_list()
if (commentlist.length != 0) {
// clearInterval(jiance)
commentlist.forEach(c => {
let pid = get_pid(c)
if (done.has(pid)) {
if (yuanyou.has(pid) && c.textContent.includes(tag1) === false) {
c.append(tag1)
}
if (zhouyou.has(pid) && c.textContent.includes(tag2) === false) {
c.append(tag2)
}
if (nongyou.has(pid) && c.textContent.includes(tag3) === false) {
c.append(tag3)
}
return
}
//console.log(pid)
let blogurl = blog + pid
// let xhr = new XMLHttpRequest()
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) {
done.add(pid)
//console.log('成功')
let st = JSON.stringify(JSON.parse(res.response).data)
if (st.includes(keyword1) && !yuanyou.has(pid)) {
c.append(tag1)
yuanyou.add(pid)
}
if (st.includes(keyword2) && !zhouyou.has(pid)) {
c.append(tag2)
zhouyou.add(pid)
}
if (st.includes(keyword3) && !nongyou.has(pid)) {
c.append(tag3)
nongyou.add(pid)
}
} else {
done.add(pid)
console.log('失败')
console.log(res)
}
},
});
});
}
}, 4000)
})();