(function () { window.addEventListener("load", () => { const aTagList = document.getElementsByTagName(`a`); const currentUrlParams = new URLSearchParams(window.location.search); const replaceUrl = { from:"https://lin.ee/1isLj0O", to:"https://t.afi-b.com/visit.php?a=914422d-u4733440" }; for (const aTag of aTagList) { if (aTag.href === "") { continue; } const aTagParams = new URLSearchParams(aTag.search); const url = new URL(aTag); console.log(aTag.href); if (url.origin.indexOf("t.afi-b.com") !== -1) { console.log(currentUrlParams.get("afbsiteid")); if (currentUrlParams.get("afbsiteid")) { aTagParams.append("p", currentUrlParams.get("afbsiteid")); } aTag.search = aTagParams.toString(); } else if (aTag.href === replaceUrl.from) { if (currentUrlParams.get("afbsiteid")) { const replaceTo = replaceUrl.to + "&p=" + currentUrlParams.get("afbsiteid"); const newHref = aTag.href.replace(replaceUrl.from, replaceTo); aTag.setAttribute("href", newHref); } } } }); })();