【油猴脚本】白嫖NL装饰

趁着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;
    }
`);

})();
```

好帖,感谢op分享!

感谢大佬,这个只能自己看见吧


@“CoolMan”#p296182

厉害了

6 还能这样 谢佬分享

感谢很赞!自己看看过瘾:huaji02:

慢慢攢NL 先過過乾癮

謝謝大佬

谢佬分享 先自娱自乐一下 看看能不能用

@“xinlan”#p296254 记得改</s>用户名<e>

如果不是自娱自乐,会不会被站长打屁股,哈哈

好家伙,人才呀

@“Vsmile”#p296307 之前的签到脚本不就被kill了吗

牛牪犇啊

自慰版?

@“GLin”#p296418

牛逼:xhj06:

这个非诚不错

自己骗下自己就很舒服了


学习了 感谢分享