趁着NL切换到Discourse之前送一波福利
[clip mp4=“https://i.imgur.com/7A4y6oP.mp4”]
将脚本内的`userName`值改为自己的`用户名`,一定注意是`用户名`而不是`昵称`
```javascript
// ==UserScript==
// @name 白嫖NodeLoc装饰
// @namespace QQ:94575594
// @version 1.0
// @description 免费使用装饰店的头像边框与用户名颜色特效
// @author chendaye
// @grant GM_addStyle
// @match https://www.nodeloc.com/*
// @run-at document-end
// @license MIT
// @downloadURL https://update.greasyfork.org/scripts/531714/%E7%99%BD%E5%AB%96NodeLoc%E8%A3%85%E9%A5%B0.user.js
// @updateURL https://update.greasyfork.org/scripts/531714/%E7%99%BD%E5%AB%96NodeLoc%E8%A3%85%E9%A5%B0.meta.js
// ==/UserScript==
(function () {
const config = {
userName: 'chendaye',
delay: 500
}
const debounce = (func, delay) => {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), delay);
};
};
const replaceUserName = (node) => {
if (node == null)
document.querySelectorAll(`[username="${config.userName}"]`).forEach(item => replaceUserName(item));
else {
let lable = node.parentNode.querySelector(".username")
if (!lable) {
replaceUserName(node.parentNode)
} else {
if (lable.querySelector(localStorage.userNameStyle)) {
return
}
lable.className = 'username ' + localStorage.userNameStyle
}
}
}
const insertBtn = () => {
document.querySelectorAll('.DecorationStoreLabel').forEach(label => {
if (label.querySelector('.btnPiao')) return;
if (label.previousElementSibling.querySelector(".DecorationItemAvatarImage")) {
const btn = Object.assign(document.createElement('button'), {
className: 'btnPiao DecorationItemLabel',
innerHTML: '白嫖头像边框',
onclick: (e) => handleImageStorage(label, e)
});
label.appendChild(btn);
}
else if (label.previousElementSibling.querySelector(".decorationItemUsernameColorStyle")) {
const btn = Object.assign(document.createElement('button'), {
className: 'btnPiao DecorationItemLabel',
innerHTML: '白嫖用户名颜色',
onclick: (e) => handleUserNameStyle(label, e)
});
label.appendChild(btn);
}
});
}
const handleUserNameStyle = (label, event) => {
try {
// 阻止事件冒泡
if (event.stopPropagation) {
event.stopPropagation();
} else {
event.cancelBubble = true;
}
const container = label.closest('.DecorationStoreContainer');
const style = container?.querySelector('.decorationItemUsernameColorStyle div');
localStorage.userNameStyle = style.className
} catch (e) {
console.error('白嫖失败:', e);
}
replaceUserName();
}
const handleImageStorage = (label, event) => {
try {
// 阻止事件冒泡
if (event.stopPropagation) {
event.stopPropagation();
} else {
event.cancelBubble = true;
}
const container = label.closest('.DecorationStoreContainer');
const img = container?.querySelector('.DecorationItemAvatarImage');
if (img?.src) {
localStorage.avatarUrl = img.src
}
} catch (e) {
console.error('白嫖失败:', e);
}
replaceAvatar();
};
const replaceAvatar = () => {
const storedSrc = localStorage.avatarUrl;
if (!storedSrc) return;
document.querySelectorAll(`[username="${config.userName}"]`).forEach(userContainer => {
const images = userContainer.querySelectorAll('img');
images.forEach(img => {
if (img.src !== storedSrc) {
img.src = storedSrc;
}
});
});
};
const begin = () => {
replaceAvatar();
replaceUserName();
insertBtn();
}
const observer = new MutationObserver(debounce((mutationsList => {
mutationsList.forEach(mutation => {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach(node => {
begin()
});
}
});
}), config.delay));
observer.observe(document.body, {
childList: true,
subtree: true
})
begin();
GM_addStyle(`
@keyframes slideIn {
from { transform: translateX(100%); }
to { transform: translateX(0); }
}
.btnPiao {
background: #4834d4;
border: none;
color: white !important;
cursor: pointer;
transition: all 0.3s;
margin-left: 5px;
}
.btnPiao:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px #4834d4;
}
`);
})();
```