复制以下全部到油猴里新建脚本保存:
// ==UserScript==
// @name 全网商家 AFF 强制替换 & 深度拦截器 (提示增强版)
// @namespace http://tampermonkey.net/
// @version 1.5
// @description 修复提示显示问题,增强针对 NodeSeek 等论坛的兼容性。
// @author Deeplook
// @match *://*/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const REPLACEMENT_RULES = [
{
name: "DMIT",
// 改为匹配整个 dmit.io
match: "dmit.io",
reg: /aff=\d+/g,
// 数字改为你喜欢的 AFFMan对应ID,默认是我的,哈哈
newAff: "aff=20350"
}
];
/**
* 安全的 UI 提示:确保在 body 准备好后显示
*/
function safeNotify(msg) {
const show = () => {
const div = document.createElement('div');
div.style = "position:fixed;top:40px;left:50%;transform:translateX(-50%);z-index:2147483647;background:#2ecc71;color:#fff;padding:12px 25px;border-radius:50px;box-shadow:0 8px 20px rgba(0,0,0,0.3);font-weight:bold;font-size:15px;text-align:center;min-width:200px;border:2px solid #fff;";
div.innerText = `🛡️ AFF 助手: ${msg}`;
document.body.appendChild(div);
console.log(`[AFF Notification] ${msg}`);
setTimeout(() => {
div.style.transition = "opacity 0.5s";
div.style.opacity = "0";
setTimeout(() => div.remove(), 500);
}, 3000);
};
if (document.body) {
show();
} else {
document.addEventListener('DOMContentLoaded', show);
}
}
function replaceLinks(el) {
const rawHref = el.getAttribute('href');
if (!rawHref) return;
let newRawHref = rawHref;
REPLACEMENT_RULES.forEach(rule => {
const normalReg = rule.reg;
const encodedReg = new RegExp(rule.reg.source.replace('=', '%3D'), 'g');
const encodedNewAff = rule.newAff.replace('=', '%3D');
// 支持整个 dmit.io
if (
newRawHref.includes(rule.match) ||
decodeURIComponent(newRawHref).includes(rule.match)
) {
newRawHref = newRawHref.replace(normalReg, rule.newAff);
newRawHref = newRawHref.replace(encodedReg, encodedNewAff);
}
});
if (rawHref !== newRawHref) {
el.setAttribute('href', newRawHref);
}
// 保留原来的鼠标提示(即使已经是自己的 AFF)
if (newRawHref.includes("aff=20350") || newRawHref.includes("aff%3D20350")) {
el.onmouseenter = () => {
console.log(`[AFF Check] 此链接已指向你的 AFF: ${newRawHref}`);
};
}
}
function checkCurrentPage() {
const url = window.location.href;
REPLACEMENT_RULES.forEach(rule => {
if (
url.includes(rule.match) &&
(rule.reg.test(url) || url.includes("aff%3D"))
) {
rule.reg.lastIndex = 0;
let newUrl = url.replace(rule.reg, rule.newAff);
const encodedReg = new RegExp(rule.reg.source.replace('=', '%3D'), 'g');
const encodedNewAff = rule.newAff.replace('=', '%3D');
newUrl = newUrl.replace(encodedReg, encodedNewAff);
if (newUrl !== url) {
safeNotify(`已成功拦截 ${rule.name} 推广并替换为你的 ID`);
window.location.replace(newUrl);
}
}
});
}
// 执行
checkCurrentPage();
const init = () => {
document.querySelectorAll('a[href]').forEach(replaceLinks);
};
const observer = new MutationObserver(mutations => {
mutations.forEach(m => {
m.addedNodes.forEach(node => {
if (node.nodeType === 1) {
if (node.tagName === 'A') {
replaceLinks(node);
} else {
node.querySelectorAll('a[href]').forEach(replaceLinks);
}
}
});
});
});
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
init();
observer.observe(document.body, {
childList: true,
subtree: true
});
});
} else {
init();
if (document.body) {
observer.observe(document.body, {
childList: true,
subtree: true
});
}
}
})();
《dmit 大妈防aff插件,自动替换aff,防止误点击》留言数:0