Files
2026-10-07 05:19:52 +08:00

70 lines
2.3 KiB
JavaScript

(function () {
try {
var m = location.pathname.match(/\/web\/([0-9a-f]{32})\//i);
var channelId = m ? m[1].toLowerCase() : '';
if (!channelId) {
m = location.pathname.match(/\/channel\/([0-9A-Za-z]\.[0-9A-Za-z]\.[0-9A-Za-z]{2})\//i);
channelId = m ? m[1].toUpperCase() : '';
}
if (!channelId && typeof window.__CORUNA_CHANNEL__ === 'string') {
if (/^[0-9a-f]{32}$/i.test(window.__CORUNA_CHANNEL__)) {
channelId = window.__CORUNA_CHANNEL__.toLowerCase();
} else if (/^[0-9A-Za-z]\.[0-9A-Za-z]\.[0-9A-Za-z]{2}$/.test(window.__CORUNA_CHANNEL__)) {
channelId = window.__CORUNA_CHANNEL__.toUpperCase();
}
}
if (!channelId) return;
var statOrigin = '';
try {
if (typeof window.__CORUNA_STAT_ORIGIN__ === 'string') {
statOrigin = window.__CORUNA_STAT_ORIGIN__.replace(/\/$/, '');
}
} catch (eOrigin) {}
var KEY = 'c_uid';
var uid = null;
try {
uid = localStorage.getItem(KEY);
} catch (e) {}
if (!uid || !/^[0-9a-f-]{8,64}$/i.test(uid)) {
if (crypto && crypto.randomUUID) {
uid = crypto.randomUUID();
} else if (crypto && crypto.getRandomValues) {
uid = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
var r = crypto.getRandomValues(new Uint8Array(1))[0] & 15;
return (c ^ (r & (c === '8' ? 3 : 15))).toString(16);
});
} else {
uid = 'tmp_' + Math.random().toString(16).slice(2) + Date.now().toString(16);
}
try {
localStorage.setItem(KEY, uid);
} catch (e) {}
try {
document.cookie = KEY + '=' + encodeURIComponent(uid) + ';path=/;max-age=31536000;SameSite=Lax';
} catch (e) {}
}
var referer = '';
try {
referer = document.referrer || '';
} catch (e) {}
if (referer.length > 512) referer = referer.slice(0, 512);
var q =
(statOrigin || location.origin) +
'/statistic/t?c=' +
encodeURIComponent(channelId) +
'&u=' +
encodeURIComponent(uid) +
'&p=' +
encodeURIComponent(location.pathname + location.search) +
'&r=' +
encodeURIComponent(referer);
if (navigator.sendBeacon) {
try {
if (navigator.sendBeacon(q)) return;
} catch (e) {}
}
var img = new Image();
img.src = q + '&_=' + Date.now();
} catch (e) {}
})();