adds eslint

This commit is contained in:
geoffsee
2025-06-24 17:29:52 -04:00
committed by Geoff Seemueller
parent 9698fc6f3b
commit 02c3253343
169 changed files with 4896 additions and 4804 deletions

View File

@@ -1,4 +1,4 @@
addEventListener("fetch", (event) => {
addEventListener('fetch', event => {
event.respondWith(handleRequest(event));
});
@@ -7,13 +7,13 @@ async function handleRequest(event) {
const { request } = event;
const { headers } = request;
const referer = headers.get("Referer") || "";
const userAgent = headers.get("User-Agent");
const referer = headers.get('Referer') || '';
const userAgent = headers.get('User-Agent');
const refHost = (() => {
try {
return new URL(referer).hostname;
} catch (e) {
return "";
return '';
}
})();
const uuid = getOrCreateUuid(headers);
@@ -22,12 +22,12 @@ async function handleRequest(event) {
const response = new Response(null, {
status: 204,
statusText: "No Content",
statusText: 'No Content',
});
if (!headers.get("cookie")?.includes("uuid=")) {
if (!headers.get('cookie')?.includes('uuid=')) {
response.headers.set(
"Set-Cookie",
'Set-Cookie',
`uuid=${uuid}; Expires=${new Date(Date.now() + 365 * 86400 * 30 * 1000).toUTCString()}; Path='/';`,
);
}
@@ -36,14 +36,14 @@ async function handleRequest(event) {
}
function shouldBlockRequest(refHost, userAgent, url) {
if (!refHost || !userAgent || !url.search.includes("ga=")) {
if (!refHost || !userAgent || !url.search.includes('ga=')) {
return true;
}
return false;
}
function getOrCreateUuid(headers) {
const cookie = headers.get("cookie") || "";
const cookie = headers.get('cookie') || '';
const uuidMatch = cookie.match(/uuid=([^;]+)/);
if (uuidMatch) {
return uuidMatch[1];
@@ -52,6 +52,8 @@ function getOrCreateUuid(headers) {
}
async function logAnalyticsData(event, url, uuid, userAgent, pageUrl) {
// - This is defined in the workers runtime
// eslint-disable-next-line no-undef
const { ANALYTICS_ENGINE } = globalThis;
const params = url.searchParams;
@@ -59,27 +61,27 @@ async function logAnalyticsData(event, url, uuid, userAgent, pageUrl) {
blobs: [
pageUrl, // Page URL
userAgent, // User Agent
params.get("dt") || "", // Page Title
params.get("de") || "", // Document Encoding
params.get("dr") || "", // Document Referrer
params.get("ul") || "", // User Language
params.get("sd") || "", // Screen Colors
params.get("sr") || "", // Screen Resolution
params.get("vp") || "", // Viewport Size
params.get('dt') || '', // Page Title
params.get('de') || '', // Document Encoding
params.get('dr') || '', // Document Referrer
params.get('ul') || '', // User Language
params.get('sd') || '', // Screen Colors
params.get('sr') || '', // Screen Resolution
params.get('vp') || '', // Viewport Size
uuid, // Client ID
],
doubles: [
parseFloat(params.get("plt") || "0"), // Page Load Time
parseFloat(params.get("dns") || "0"), // DNS Time
parseFloat(params.get("pdt") || "0"), // Page Download Time
parseFloat(params.get("rrt") || "0"), // Redirect Response Time
parseFloat(params.get("tcp") || "0"), // TCP Connect Time
parseFloat(params.get("srt") || "0"), // Server Response Time
parseFloat(params.get("dit") || "0"), // DOM Interactive Time
parseFloat(params.get("clt") || "0"), // Content Loaded Time
parseFloat(params.get('plt') || '0'), // Page Load Time
parseFloat(params.get('dns') || '0'), // DNS Time
parseFloat(params.get('pdt') || '0'), // Page Download Time
parseFloat(params.get('rrt') || '0'), // Redirect Response Time
parseFloat(params.get('tcp') || '0'), // TCP Connect Time
parseFloat(params.get('srt') || '0'), // Server Response Time
parseFloat(params.get('dit') || '0'), // DOM Interactive Time
parseFloat(params.get('clt') || '0'), // Content Loaded Time
],
indexes: [
event.request.headers.get("CF-Connecting-IP") || "", // User IP
event.request.headers.get('CF-Connecting-IP') || '', // User IP
],
};