那试一下这个
[JavaScript] 纯文本查看 复制代码 (function () {
'use strict';
const elements = [
{
text: '山H100',
mark: '工资/假期'
},
'其他需要显示的内容',
{
text: '显示的内容333',
tag: 'a',
mark: '后缀内容'
},
]
window.onload = function () {
const getElementsByText = (text, tag='a') => {
return Array.from(document.querySelectorAll(tag)).filter(element => element.textContent.includes(text));
}
elements.forEach(item => {
let ele;
if (typeof item === 'object') {
ele = getElementsByText(item.text, item.tag || 'a');
} else {
ele = getElementsByText(item)
}
if (ele.length !== 0) {
const myElement = ele[0];
//myElement.style.WebkitTextStrokeColor = "red"; // 设置描边颜色(Safari)
//myElement.style.MozTextStrokeColor = "blue"; // 设置描边颜色(Firefox)
//myElement.style.WebkitTextStrokeWidth = "1px"; // 设置描边大小(Safari)
//myElement.style.MozTextStrokeWidth = "1px"; // 设置描边大小(Firefox)
myElement.style.color = "red";
if (item.mark) {
const oldText = myElement.textContent;
const mark = document.createElement('span');
mark.style.fontSize = '10px';
mark.style.marginLeft = '1px';
mark.textContent = `(${item.mark})`;
// 拼接原来的文本和标记
myElement.textContent = '';
myElement.appendChild(document.createTextNode(oldText));
myElement.appendChild(mark);
}
}
});
}
})();
放到油猴脚本里添加,参考上面发的帖子 |