Update fontScript/index.js

This commit is contained in:
jb 2024-11-28 21:10:40 +01:00
parent 809aa6b21b
commit acd33ee096

View file

@ -1,7 +1,7 @@
(async () => { (async () => {
const website = "https://example.tld/"; // Replace with the URL of the website 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 path to the CSS file const pathToCss = "path/to/css"; // Replace with the relative path to the CSS file
const cssUrl = website + pathToCss; const cssUrl = `${website}/${pathToCss}`; // Combine base URL and CSS path
try { try {
// Fetch the CSS file // Fetch the CSS file
@ -9,7 +9,7 @@
const cssText = await response.text(); const cssText = await response.text();
// Use a regular expression to extract the font file path // Use a regular expression to extract the font file path
const fontMatch = cssText.match(/url\(['"]?(.*?web-font\.(otf|ttf|woff|woff2|eot))['"]?\)/); const fontMatch = cssText.match(/url\(['"]?(.*?\.(otf|ttf|woff|woff2|eot))['"]?\)/);
if (fontMatch && fontMatch[1]) { if (fontMatch && fontMatch[1]) {
const resolvedFontPath = new URL(fontMatch[1], cssUrl).href; // Resolve relative path const resolvedFontPath = new URL(fontMatch[1], cssUrl).href; // Resolve relative path