34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
(async () => {
|
|
// Use window.location.origin or fallback to "https://website.tld"
|
|
const website = window.location.origin || "https://website.tld";
|
|
|
|
try {
|
|
// Find the first <link> 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();
|
|
|
|
// Use a regular expression to extract the font file path
|
|
const fontMatch = cssText.match(/url\(['"]?(.*?\.(otf|ttf|woff|woff2|eot))['"]?\)/);
|
|
|
|
if (fontMatch && fontMatch[1]) {
|
|
const resolvedFontPath = new URL(fontMatch[1], cssUrl).href; // Resolve relative path
|
|
console.log(`Found font URL: ${resolvedFontPath}`);
|
|
} else {
|
|
console.log('Font not found in the CSS file.');
|
|
}
|
|
} catch (error) {
|
|
console.error('Error fetching or parsing the CSS file:', error);
|
|
}
|
|
})(); |