(function() {
'use strict';
const CONFIG = {
authorNames: ["瑞娅_Rhea"],
scrollInterval: 1000,
maxScrollAttempts: 5,
checkInterval: 500
};
const logContainer = document.createElement('div');
GM_addStyle(`
.logger {
position: fixed;
bottom: 20px;
right: 20px;
background: rgba(0,0,0,0.8);
color: #fff;
padding: 10px;
border-radius: 5px;
max-width: 300px;
max-height: 200px;
overflow-y: auto;
font-family: monospace;
z-index: 9999;
}
`);
logContainer.className = 'logger';
document.body.appendChild(logContainer);
function log(message) {
const entry = document.createElement('div');
entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
logContainer.appendChild(entry);
logContainer.scrollTop = logContainer.scrollHeight;
}
function deepQuerySelectorAll(selector, root = document) {
const results = [];
const searchInShadow = (node) => {
try {
const matches = node.querySelectorAll(selector);
if (matches.length > 0) {
results.push(...matches)
}
if (node.shadowRoot) {
searchInShadow(node.shadowRoot);
}
for (const child of node.children) {
searchInShadow(child)
}
} catch (e) {
console.warn('Shadow DOM访问异常:', e);
}
};
searchInShadow(root.body || root);
return Array.from(new Set(results));
}
function checkAuthor() {
const authorDiv = document.querySelector('.opus-module-author__name');
return authorDiv && CONFIG.authorNames.includes(authorDiv.textContent.trim());
}
async function fullScrollLoad() {
let lastHeight = 0;
let attempts = 0;
return new Promise((resolve) => {
const scrollInterval = setInterval(() => {
window.scrollTo(0, document.body.scrollHeight);
const newHeight = document.documentElement.scrollHeight;
if (newHeight === lastHeight) {
if (++attempts >= CONFIG.maxScrollAttempts) {
clearInterval(scrollInterval);
resolve();
}
} else {
lastHeight = newHeight;
attempts = 0;
}
}, CONFIG.scrollInterval);
});
}
function scrollToElementCenter(element) {
const rect = element.getBoundingClientRect();
const centerY = rect.top + rect.height / 2 - window.innerHeight / 2;
window.scrollBy({
top: centerY,
behavior: 'smooth'
});
}
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms + Math.random() * 500));
async function performLike() {
const doms = deepQuerySelectorAll('#like button');
log('找到' + doms.length + '个点赞按钮');
if (!doms.length) {
log('错误:找不到点赞按钮');
return false;
}
for (let i in doms) {
await sleep(CONFIG.checkInterval)
const icon = doms[i].querySelector('bili-icon');
scrollToElementCenter(doms[i])
if (icon && icon.style.cssText.includes('--brand_blue')) {
log('第' + (Number(i) + 1) + '个已经点赞过');
} else {
doms[i].click();
log('第' + (Number(i) + 1) + '个点赞成功');
}
}
log('点赞完成');
}
async function main() {
if (!checkAuthor()) {
return;
}
log('开始滚动加载内容...');
await fullScrollLoad();
log('内容加载完成,开始点赞');
performLike();
}
setTimeout(main, 2000);
})();