Greasy Fork is available in English.
这是一个查询B站用户成分的脚本
当前为
// ==UserScript==
// @name 成分查询-B站
// @namespace YuriMaggot
// @version 1.1.1
// @description 这是一个查询B站用户成分的脚本
// @author Light Yagami
// @match https://www.bilibili.com/video/*
// @match https://t.bilibili.com/*
// @match https://space.bilibili.com/*
// @icon https://gss0.bdstatic.com/6LZ1dD3d1sgCo2Kml5_Y_D3/sys/portrait/item/tb.1.403ed6f0.KeS29MO38cMTCTAl7gU1Iw?t=1708414222
// @grant GM_xmlhttpRequest
// @license MPL
// ==/UserScript==
// 数据库
let data =
[
{
"uid": "",
"count": 0,
"tags":[
""
]
}
];
// 用来搜索索引的数组
let uid_array = [""];
class Utils
{
// 添加新节点
static AddElement(target_element, class_name, text_content, style_text)
{
let new_element = document.createElement('div');
new_element.className = class_name;
new_element.textContent = text_content;
new_element.style.cssText = style_text;
let parent = target_element.parentNode;
if (parent.lastChild == target_element){
parent.appendChild(new_element);
}
else{
parent.insertBefore(new_element, target_element.nextSibling);
}
}
}
class Init
{
// 初始化数据库的数据
static InitJsonData()
{
GM_xmlhttpRequest(
{
method: 'GET',
url: 'https://gitee.com/light-yagami/yuri-maggot/raw/master/Data.json',
onload: function(response)
{
data = JSON.parse(response.responseText);
uid_array = data.map(function(o) {
return o.uid;
});
}
});
}
// 初始化 CSS 样式
static InitCssStyle()
{
let style = document.createElement('style');
document.head.appendChild(style);
style.sheet.insertRule(`
@keyframes gradient-animation
{
0%, 100% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
}`, 0);
style.sheet.insertRule(`
.dynamic-gradient-text
{
background: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
background-size: 500% 500%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: gradient-animation 10s linear infinite;
}`, 1);
}
}
class VideoPage
{
// 视频页面数据更新
static Update(reply_list)
{
for(let i = 0; i < reply_list.getElementsByClassName('reply-item').length; i++)
{
// reply-list[i].reply-item.root-reply-container.content-warp.user-info
let user_info = reply_list.getElementsByClassName('reply-item')[i].getElementsByClassName('root-reply-container')[0].getElementsByClassName('content-warp')[0].getElementsByClassName('user-info')[0];
let user_name = user_info.getElementsByClassName('user-name')[0];
// reply-list[i].reply-item.root-reply-container.content-warp.user-info.user-name
let user_info_index = uid_array.indexOf(user_name.getAttribute('data-user-id'));
if(!user_info.getElementsByClassName('dynamic-gradient-text').length && !user_info.getElementsByClassName('normal-user').length)
{
if(user_info_index != -1)
{
user_name.style.color = 'red';
user_name.style.fontWeight = 'bold';
Utils.AddElement(user_info.getElementsByClassName('svg-icon')[0], 'dynamic-gradient-text', '<次数: ' + data[user_info_index].count + '>', 'font-weight: bold;');
for(let uii = 0; uii < data[user_info_index].tags.length; uii++){
Utils.AddElement(user_name, 'dynamic-gradient-text', '【' + data[user_info_index].tags[uii] + '】', 'font-weight: bold;');
}
}
else
{
user_name.style.color = 'black';
user_name.style.fontWeight = 'bold';
Utils.AddElement(user_name, 'normal-user', '【路人】', 'color: grey; font-weight: bold;');
}
}
// reply-list[i].reply-item.sub-reply-container.sub-reply-list
let sub_reply_list = reply_list.getElementsByClassName('reply-item')[i].getElementsByClassName('sub-reply-container')[0].getElementsByClassName('sub-reply-list')[0];
for(let j = 0; j < sub_reply_list.getElementsByClassName('sub-reply-item').length; j++)
{
// reply-list[i].reply-item.sub-reply-container.sub-reply-list.sub-reply-item[j].sub-user-info
let sub_user_info = sub_reply_list.getElementsByClassName('sub-reply-item')[j].getElementsByClassName('sub-user-info')[0];
let sub_user_name = sub_user_info.getElementsByClassName('sub-user-name')[0];
// reply-list[i].reply-item.sub-reply-container.sub-reply-list.sub-reply-item[j].sub-user-info.sub-user-name
let sub_user_info_index = uid_array.indexOf(sub_user_name.getAttribute('data-user-id'));
if(!sub_user_info.getElementsByClassName('dynamic-gradient-text').length && !sub_user_info.getElementsByClassName('normal-user').length)
{
if(sub_user_info_index != -1)
{
sub_user_name.style.color = 'red';
sub_user_name.style.fontWeight = 'bold';
Utils.AddElement(sub_user_info.getElementsByClassName('svg-icon')[0], 'dynamic-gradient-text', '<次数: ' + data[sub_user_info_index].count + '>', 'font-weight: bold;');
for(let suii = 0; suii < data[sub_user_info_index].tags.length; suii++){
Utils.AddElement(sub_user_name, 'dynamic-gradient-text', '【' + data[sub_user_info_index].tags[suii] + '】', 'font-weight: bold;');
}
}
else
{
sub_user_name.style.color = 'black';
sub_user_name.style.fontWeight = 'bold';
Utils.AddElement(sub_user_name, 'normal-user', '【路人】', 'color: grey; font-weight: bold;');
}
}
}
}
}
// 首次运行
static FirstRun(reply_list)
{
VideoPage.Update(reply_list);
}
// 监视翻页带来的评论更新
static ReplyListener(reply_list)
{
let config = { childList: true, subtree: true };
let observer = new MutationObserver(function(mutationsList)
{
for (let mutation of mutationsList)
{
if (mutation.type == 'childList')
{
for (let node of mutation.addedNodes)
{
if (node && node.classList && node.classList.contains('reply-loading'))
{
setTimeout(function()
{
VideoPage.Update(reply_list);
}, 3000);
}
}
}
}
});
observer.observe(reply_list, config);
}
// 监视子评论更新
static SubReplyListener(reply_list)
{
reply_list.addEventListener('mouseup', function()
{
setTimeout(function()
{
VideoPage.Update(reply_list);
}, 3000);
});
}
}
class SpacePage
{
// 个人空间页面数据更新
static Update(bili_dyn_list)
{
for(let i = 0; i < bili_dyn_list.getElementsByClassName('bili-dyn-list__items')[0].getElementsByClassName('bili-dyn-list__item').length; i++)
{
// bili_dyn_list.bili-dyn-list__items.bili-dyn-list__item[i].bili-dyn-item
let bili_dyn_item = bili_dyn_list.getElementsByClassName('bili-dyn-list__items')[0].getElementsByClassName('bili-dyn-list__item')[i].getElementsByClassName('bili-dyn-item')[0];
if(bili_dyn_item.getElementsByClassName('bili-dyn-item__panel').length)
{
// bili_dyn_item.bili-dyn-item__panel.bili-comment-container.bili-comment.comment-container.reply-warp.reply-list
let reply_list = bili_dyn_item.getElementsByClassName('bili-dyn-item__panel')[0].getElementsByClassName('bili-comment-container')[0].getElementsByClassName('bili-comment')[0].getElementsByClassName('comment-container')[0].getElementsByClassName('reply-warp')[0].getElementsByClassName('reply-list')[0];
for(let j = 0; j < reply_list.getElementsByClassName('reply-item').length; j++)
{
// reply-list[i].reply-item.root-reply-container.content-warp.user-info
let user_info = reply_list.getElementsByClassName('reply-item')[j].getElementsByClassName('root-reply-container')[0].getElementsByClassName('content-warp')[0].getElementsByClassName('user-info')[0];
let user_name = user_info.getElementsByClassName('user-name')[0];
// reply-list[i].reply-item.root-reply-container.content-warp.user-info.user-name
let user_info_index = uid_array.indexOf(user_name.getAttribute('data-user-id'));
if(!user_info.getElementsByClassName('dynamic-gradient-text').length && !user_info.getElementsByClassName('normal-user').length)
{
if(user_info_index != -1)
{
user_name.style.color = 'red';
user_name.style.fontWeight = 'bold';
Utils.AddElement(user_info.getElementsByClassName('svg-icon')[0], 'dynamic-gradient-text', '<次数: ' + data[user_info_index].count + '>', 'font-weight: bold;');
for(let uii = 0; uii < data[user_info_index].tags.length; uii++){
Utils.AddElement(user_name, 'dynamic-gradient-text', '【' + data[user_info_index].tags[uii] + '】', 'font-weight: bold;');
}
}
else
{
user_name.style.color = 'black';
user_name.style.fontWeight = 'bold';
Utils.AddElement(user_name, 'normal-user', '【路人】', 'color: grey; font-weight: bold;');
}
}
// reply-list[i].reply-item.sub-reply-container.sub-reply-list
let sub_reply_list = reply_list.getElementsByClassName('reply-item')[j].getElementsByClassName('sub-reply-container')[0].getElementsByClassName('sub-reply-list')[0];
for(let k = 0; k < sub_reply_list.getElementsByClassName('sub-reply-item').length; k++)
{
// reply-list[i].reply-item.sub-reply-container.sub-reply-list.sub-reply-item[j].sub-user-info
let sub_user_info = sub_reply_list.getElementsByClassName('sub-reply-item')[k].getElementsByClassName('sub-user-info')[0];
let sub_user_name = sub_user_info.getElementsByClassName('sub-user-name')[0];
// reply-list[i].reply-item.sub-reply-container.sub-reply-list.sub-reply-item[j].sub-user-info.sub-user-name
let sub_user_info_index = uid_array.indexOf(sub_user_name.getAttribute('data-user-id'));
if(!sub_user_info.getElementsByClassName('dynamic-gradient-text').length && !sub_user_info.getElementsByClassName('normal-user').length)
{
if(sub_user_info_index != -1)
{
sub_user_name.style.color = 'red';
sub_user_name.style.fontWeight = 'bold';
Utils.AddElement(sub_user_info.getElementsByClassName('svg-icon')[0], 'dynamic-gradient-text', '<次数: ' + data[sub_user_info_index].count + '>', 'font-weight: bold;');
for(let suii = 0; suii < data[sub_user_info_index].tags.length; suii++){
Utils.AddElement(sub_user_name, 'dynamic-gradient-text', '【' + data[sub_user_info_index].tags[suii] + '】', 'font-weight: bold;');
}
}
else
{
sub_user_name.style.color = 'black';
sub_user_name.style.fontWeight = 'bold';
Utils.AddElement(sub_user_name, 'normal-user', '【路人】', 'color: grey; font-weight: bold;');
}
}
}
}
}
}
}
// 首次运行
static FirstRun(bili_dyn_list)
{
SpacePage.Update(bili_dyn_list);
}
// 监视页面动态更新
static ReplyListener(bili_dyn_list)
{
let target_node = bili_dyn_list.getElementsByClassName('bili-dyn-list-loading')[0];
let config = { attributes: true, attributeFilter: ['style'] };
let observer = new MutationObserver(function(mutationsList)
{
for(let mutation of mutationsList)
{
if (mutation.type == 'attributes' && mutation.attributeName == 'style' && target_node.style.display != 'none')
{
setTimeout(function()
{
SpacePage.Update(bili_dyn_list);
}, 3000);
}
}
});
observer.observe(target_node, config);
}
// 监视子评论更新 & 动态页面展开
static SubReplyListener(bili_dyn_list)
{
bili_dyn_list.addEventListener('mouseup', function()
{
setTimeout(function()
{
SpacePage.Update(bili_dyn_list);
}, 3000);
});
}
}
class MomentPage
{
// 动态页面数据更新
static Update(reply_list)
{
for(let i = 0; i < reply_list.getElementsByClassName('reply-item').length; i++)
{
// reply-list[i].reply-item.root-reply-container.content-warp.user-info
let user_info = reply_list.getElementsByClassName('reply-item')[i].getElementsByClassName('root-reply-container')[0].getElementsByClassName('content-warp')[0].getElementsByClassName('user-info')[0];
let user_name = user_info.getElementsByClassName('user-name')[0];
// reply-list[i].reply-item.root-reply-container.content-warp.user-info.user-name
let user_info_index = uid_array.indexOf(user_name.getAttribute('data-user-id'));
if(!user_info.getElementsByClassName('dynamic-gradient-text').length && !user_info.getElementsByClassName('normal-user').length)
{
if(user_info_index != -1)
{
user_name.style.color = 'red';
user_name.style.fontWeight = 'bold';
Utils.AddElement(user_info.getElementsByClassName('svg-icon')[0], 'dynamic-gradient-text', '<次数: ' + data[user_info_index].count + '>', 'font-weight: bold;');
for(let uii = 0; uii < data[user_info_index].tags.length; uii++){
Utils.AddElement(user_name, 'dynamic-gradient-text', '【' + data[user_info_index].tags[uii] + '】', 'font-weight: bold;');
}
}
else
{
user_name.style.color = 'black';
user_name.style.fontWeight = 'bold';
Utils.AddElement(user_name, 'normal-user', '【路人】', 'color: grey; font-weight: bold;');
}
}
// reply-list[i].reply-item.sub-reply-container.sub-reply-list
let sub_reply_list = reply_list.getElementsByClassName('reply-item')[i].getElementsByClassName('sub-reply-container')[0].getElementsByClassName('sub-reply-list')[0];
for(let j = 0; j < sub_reply_list.getElementsByClassName('sub-reply-item').length; j++)
{
// reply-list[i].reply-item.sub-reply-container.sub-reply-list.sub-reply-item[j].sub-user-info
let sub_user_info = sub_reply_list.getElementsByClassName('sub-reply-item')[j].getElementsByClassName('sub-user-info')[0];
let sub_user_name = sub_user_info.getElementsByClassName('sub-user-name')[0];
// reply-list[i].reply-item.sub-reply-container.sub-reply-list.sub-reply-item[j].sub-user-info.sub-user-name
let sub_user_info_index = uid_array.indexOf(sub_user_name.getAttribute('data-user-id'));
if(!sub_user_info.getElementsByClassName('dynamic-gradient-text').length && !sub_user_info.getElementsByClassName('normal-user').length)
{
if(sub_user_info_index != -1)
{
sub_user_name.style.color = 'red';
sub_user_name.style.fontWeight = 'bold';
Utils.AddElement(sub_user_info.getElementsByClassName('svg-icon')[0], 'dynamic-gradient-text', '<次数: ' + data[sub_user_info_index].count + '>', 'font-weight: bold;');
for(let suii = 0; suii < data[sub_user_info_index].tags.length; suii++){
Utils.AddElement(sub_user_name, 'dynamic-gradient-text', '【' + data[sub_user_info_index].tags[suii] + '】', 'font-weight: bold;');
}
}
else
{
sub_user_name.style.color = 'black';
sub_user_name.style.fontWeight = 'bold';
Utils.AddElement(sub_user_name, 'normal-user', '【路人】', 'color: grey; font-weight: bold;');
}
}
}
}
}
// 首次运行
static FirstRun(reply_list)
{
MomentPage.Update(reply_list);
}
// 监视评论更新
static ReplyListener(reply_list)
{
let config = { childList: true, subtree: true };
let observer = new MutationObserver(function(mutationsList)
{
for (let mutation of mutationsList)
{
if (mutation.type == 'childList')
{
for (let node of mutation.addedNodes)
{
if (node && node.classList && node.classList.contains('reply-loading'))
{
setTimeout(function()
{
MomentPage.Update(reply_list);
}, 3000);
}
}
}
}
});
observer.observe(reply_list, config);
}
// 监视子评论更新
static SubReplyListener(reply_list)
{
reply_list.addEventListener('mouseup', function()
{
setTimeout(function()
{
MomentPage.Update(reply_list);
}, 3000);
});
}
}
(function()
{
'use strict';
// 初始化数据
Init.InitJsonData();
setTimeout(function()
{
// 初始化 CSS 样式
Init.InitCssStyle();
// 获取当前页面的 URL
let cur_url = window.location.href;
if (cur_url.includes('space.bilibili.com'))
{
// 个人空间
let bili_dyn_list = document.querySelector("#page-dynamic > div.col-1 > div");
SpacePage.FirstRun(bili_dyn_list);
SpacePage.ReplyListener(bili_dyn_list);
SpacePage.SubReplyListener(bili_dyn_list);
}
else if (cur_url.includes('www.bilibili.com/video'))
{
// 视频
let reply_list = document.querySelector("#comment > div > div > div > div.reply-warp > div.reply-list");
VideoPage.FirstRun(reply_list);
VideoPage.ReplyListener(reply_list);
VideoPage.SubReplyListener(reply_list);
}
else if (cur_url.includes('t.bilibili.com'))
{
// 动态
let reply_list = document.querySelector("#app > div.content > div.card > div.bili-tabs.dyn-tabs > div.bili-tabs__content > div:nth-child(1) > div > div > div > div > div.reply-warp > div.reply-list");
MomentPage.FirstRun(reply_list);
MomentPage.ReplyListener(reply_list);
MomentPage.SubReplyListener(reply_list);
}
}, 8000);
})();