修改完成
This commit is contained in:
@@ -37,6 +37,37 @@ window.CURRENT_CONFIG = window.ENV[window.CURRENT_ENV];
|
||||
window.NavigationUtil = (function (window, document) {
|
||||
const blockedProtocols = /^(?:javascript|data|vbscript|mailto|tel):/i;
|
||||
|
||||
function inviteCodeFromUrl(url) {
|
||||
try {
|
||||
return String(new URL(url || window.location.href, window.location.href).searchParams.get('inviteCode') || '').trim();
|
||||
} catch (error) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function isRegisterUrl(url) {
|
||||
try {
|
||||
return /(?:^|\/)reg\.html$/i.test(new URL(url, window.location.href).pathname);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function withReferralInviteCode(url, inviteCode) {
|
||||
const destination = String(url || '').trim();
|
||||
if (!destination || !isRegisterUrl(destination)) return destination;
|
||||
const code = String(inviteCode || inviteCodeFromUrl(window.location.href)).trim();
|
||||
if (!code) return destination;
|
||||
const target = new URL(destination, window.location.href);
|
||||
if (!target.searchParams.get('inviteCode')) target.searchParams.set('inviteCode', code);
|
||||
return target.href;
|
||||
}
|
||||
|
||||
function referralRegisterUrl(referralUrl, inviteCode) {
|
||||
const code = String(inviteCode || inviteCodeFromUrl(referralUrl)).trim();
|
||||
return code ? withReferralInviteCode('reg.html', code) : '';
|
||||
}
|
||||
|
||||
function shouldOpenInNewTab(anchor) {
|
||||
const href = (anchor.getAttribute('href') || '').trim();
|
||||
|
||||
@@ -49,6 +80,10 @@ window.NavigationUtil = (function (window, document) {
|
||||
return;
|
||||
}
|
||||
|
||||
const href = anchor.getAttribute('href') || '';
|
||||
const referralHref = withReferralInviteCode(href);
|
||||
if (referralHref !== href) anchor.setAttribute('href', referralHref);
|
||||
|
||||
if (anchor.target !== '_blank') {
|
||||
anchor.target = '_blank';
|
||||
}
|
||||
@@ -100,7 +135,7 @@ window.NavigationUtil = (function (window, document) {
|
||||
|
||||
return {
|
||||
open(url) {
|
||||
const destination = String(url || '').trim();
|
||||
const destination = withReferralInviteCode(url);
|
||||
|
||||
if (!destination) {
|
||||
return null;
|
||||
@@ -113,6 +148,9 @@ window.NavigationUtil = (function (window, document) {
|
||||
}
|
||||
|
||||
return openedWindow;
|
||||
}
|
||||
},
|
||||
|
||||
withReferralInviteCode,
|
||||
referralRegisterUrl
|
||||
};
|
||||
})(window, document);
|
||||
|
||||
Reference in New Issue
Block a user