47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
(function () {
|
|
try {
|
|
var m = location.pathname.match(/\/web\/([0-9a-f]{32})\//i);
|
|
if (!m) return;
|
|
var channelId = m[1].toLowerCase();
|
|
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 q =
|
|
location.origin +
|
|
'/statistic/t?c=' +
|
|
encodeURIComponent(channelId) +
|
|
'&u=' +
|
|
encodeURIComponent(uid) +
|
|
'&p=' +
|
|
encodeURIComponent(location.pathname + location.search);
|
|
if (navigator.sendBeacon) {
|
|
try {
|
|
if (navigator.sendBeacon(q)) return;
|
|
} catch (e) {}
|
|
}
|
|
var img = new Image();
|
|
img.referrerPolicy = 'no-referrer';
|
|
img.src = q + '&_=' + Date.now();
|
|
} catch (e) {}
|
|
})();
|