如图所示,这个脚本就是用来隐藏已经过期和已经用完的邀请码的,这样就可以方便邀请码的管理了
使用前

使用后

[reply]
```
// ==UserScript==
// @name NodeLoc Hide Code
// @namespace http://tampermonkey.net/
// @version 1.0.4
// @description 隐藏过期和已售罄的商品项
// @author 叫我沈同学
// @match https://www.nodeloc.com/*
// @grant none
// ==/UserScript==
(function () {
‘use strict’;
const hideExpiredItems = () => {
document.querySelectorAll('li.expired').forEach(li => {
li.style.display = 'none';
});
document.querySelectorAll('li.copyable-item').forEach(li => {
const pList = li.querySelectorAll('p');
pList.forEach(p => {
if (p.textContent.trim() === '剩余可用: 0') {
li.style.display = 'none';
}
});
});
};
hideExpiredItems();
const observeAjax = () => {
const send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function () {
this.addEventListener('load', () => {
setTimeout(hideExpiredItems, 500);
});
return send.apply(this, arguments);
};
};
const observeFetch = () => {
const originalFetch = window.fetch;
window.fetch = function () {
return originalFetch.apply(this, arguments).then(response => {
setTimeout(hideExpiredItems, 500);
return response;
});
};
};
const observer = new MutationObserver((mutations) => {
let needsUpdate = false;
mutations.forEach(mutation => {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
needsUpdate = true;
}
});
if (needsUpdate) {
setTimeout(hideExpiredItems, 500);
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
observeAjax();
observeFetch();
let timeoutId;
const debouncedHideExpiredItems = () => {
clearTimeout(timeoutId);
timeoutId = setTimeout(hideExpiredItems, 300);
};
window.addEventListener('load', debouncedHideExpiredItems);
window.addEventListener('DOMContentLoaded', debouncedHideExpiredItems);
window.addEventListener('scroll', debouncedHideExpiredItems);
})();
```
[/reply]