2022/9/11 16:25:30
目前為
// ==UserScript==
// @name 原神/明日方舟/王者荣耀玩家指示器(可扩展) - bilibili.com
// @namespace Violentmonkey Scripts
// @match https://www.bilibili.com/video/*
// @grant none
// @version 1.0
// @author -
// @description 2022/9/11 16:25:30
// @grant GM_xmlhttpRequest
// @license MIT
// ==/UserScript==
(function() {
const bili_new = document.getElementsByClassName('item goback').length != 0;
const bili_url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?&host_mid='
const match = [
{
name:'[原神玩家]',
color:"red",
keyword:['原神','刻晴']
},
{
name:'[明日方舟玩家]',
color:"black",
keyword:['明日方舟']
},
{
name:'[王者荣耀玩家]',
color:"blue",
keyword:['王者荣耀']
}
]
const ys = new Set()
console.log('ok')
const bili_get_comment_list = () => {
if (bili_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')
}
}
const get_pid = (c) => {
if (bili_new) {
return c.dataset['userId']
} else {
return c.children[0]['href'].replace(/[^\d]/g, "")
}
}
const last_bili_comment_length = bili_get_comment_list().length;
const now_bili_comment_length = 0;
const targetNode = document.getElementsByClassName('common')[0];
const config = {
attributes: true,
childList: true,
subtree: true
};
const callback = function (mutationsList, observer) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
if (mutation.target.className.toString() == 'comment-list ') {
console.log("评论增加");
let bgcl = bili_get_comment_list()
bgcl.forEach(c => {
let pid = get_pid(c);
GM_xmlhttpRequest({
method: "get",
url: bili_url + pid,
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) {
let st = JSON.stringify(JSON.parse(res.response).data)
match.forEach(m =>{
m['keyword'].forEach(k=>{
if (st.includes(k)){
let toAppend = document.createElement("DIV");
toAppend.style.color = m['color'];
toAppend.style.display = 'inline-block'
toAppend.innerHTML = m['name'];
c.append(toAppend);
return false;
}
})
})
},
});
});
}
}
}
}
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
})();