本帖最后由 Cristy 于 2025-4-7 10:24 编辑
效果:
这里可以自定义设置样式,格式是css代码:
代码上传有点问题 ,自动加了一些没用的标签,已经重新替换格式上传了:
(function() {
'use strict';
const defaultStyles = {
fontWeight: 'bold',
color: 'red',
fontSize: '16px'
};
const styles = {
fontWeight: GM_getValue('fontWeight', defaultStyles.fontWeight),
color: GM_getValue('color', defaultStyles.color),
fontSize: GM_getValue('fontSize', defaultStyles.fontSize)
};
GM_registerMenuCommand("设置链接样式", function() {
const newFontWeight = prompt("请输入字体粗细 (例如: bold, normal):", styles.fontWeight);
if (newFontWeight) {
styles.fontWeight = newFontWeight;
GM_setValue('fontWeight', styles.fontWeight);
}
const newColor = prompt("请输入字体颜色 (例如: red, #ff0000):", styles.color);
if (newColor) {
styles.color = newColor;
GM_setValue('color', styles.color);
}
const newFontSize = prompt("请输入字体大小 (例如: 16px, 1em):", styles.fontSize);
if (newFontSize) {
styles.fontSize = newFontSize;
GM_setValue('fontSize', styles.fontSize);
}
alert("样式已更新!");
});
function checkAndModify() {
const rows = document.querySelectorAll('tbody tr');
console.log(`找到 ${rows.length} 行`);
rows.forEach(row => {
const ths = row.querySelectorAll('th.common');
let hasReward = false;
ths.forEach(th => {
const span = th.querySelector('span');
if (span) {
console.log(`检查 th 中的 span: ${span.textContent}`);
if (span.textContent.includes('回帖奖励')) {
hasReward = true;
console.log('找到包含“回帖奖励”的 span');
}
}
});
if (hasReward) {
console.log('对该行的 class 为 common 的 a 标签进行样式修改');
const links = row.querySelectorAll('th.common a.s.xst');
links.forEach(link => {
link.style.fontWeight = styles.fontWeight;
link.style.color = styles.color;
link.style.fontSize = styles.fontSize;
console.log(`修改链接: ${link.textContent}`);
});
} else {
console.log('该行没有包含“回帖奖励”的 span');
}
});
}
const observer = new MutationObserver(checkAndModify);
const config = { childList: true, subtree: true };
observer.observe(document.body, config);
console.log('开始观察整个文档的 body');
checkAndModify();
})();
|