From 39954c0579c8b90145a69c375a2280cae76ad0e3 Mon Sep 17 00:00:00 2001 From: jb Date: Fri, 29 Nov 2024 08:34:38 +0100 Subject: [PATCH] Update fontScript/index.js --- fontScript/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/fontScript/index.js b/fontScript/index.js index 28fbca4..0dab451 100644 --- a/fontScript/index.js +++ b/fontScript/index.js @@ -1,9 +1,20 @@ (async () => { - const website = window.location.origin; // Get the current website's base URL (or switch to "https://website.tld/") - const pathToCss = "path/to/css"; // Replace with the relative path to the CSS file - const cssUrl = `${website}/${pathToCss}`; // Combine base URL and CSS path + // Use window.location.origin or fallback to "https://website.tld" + const website = window.location.origin || "https://website.tld"; try { + // Find the first tag with an href ending in ".css" + const linkElement = Array.from(document.querySelectorAll('link')) + .find(link => link.href.endsWith('.css')); // Adjust condition if needed + + if (!linkElement) { + console.log("No CSS file found on the page."); + return; + } + + const cssUrl = linkElement.href; // Get the full URL of the CSS file + console.log(`Fetching CSS from: ${cssUrl}`); + // Fetch the CSS file const response = await fetch(cssUrl); const cssText = await response.text();