Refactor redirect URL code block into a function

This commit is contained in:
Helen Chong 2024-05-31 10:42:07 +08:00
parent a6ca591fee
commit 8eff9df6de
1 changed files with 8 additions and 4 deletions

View File

@ -2,7 +2,11 @@ const currentUrl = window.location.href;
const oldDomain = 'leilukin.neocities.org'; const oldDomain = 'leilukin.neocities.org';
const newDomain = 'leilukin.com'; const newDomain = 'leilukin.com';
if (currentUrl.includes(oldDomain)) { const redirectUrl = (oldStr, newStr) => {
const newUrl = currentUrl.replace(oldDomain, newDomain); if (currentUrl.includes(oldStr)) {
location.replace(newUrl); const newUrl = currentUrl.replace(oldStr, newStr);
} location.replace(newUrl);
}
}
redirectUrl(oldDomain, newDomain);