From 521f7f9abb9e20f7caaf423893b80c2134d1195b Mon Sep 17 00:00:00 2001 From: Quartinal Date: Tue, 14 Jan 2025 14:02:30 -0800 Subject: [PATCH] fix firefox support (thanks @qwertychomp) --- index.html | 3 ++- js/isValidTag.js | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 3a7d390..d67abbe 100644 --- a/index.html +++ b/index.html @@ -15,7 +15,8 @@ - + + diff --git a/js/isValidTag.js b/js/isValidTag.js index 75ec52d..4da2bec 100644 --- a/js/isValidTag.js +++ b/js/isValidTag.js @@ -1,8 +1,30 @@ import htmlTags from '../json/html-tags.json' with { type: 'json' }; import htmlVoidTags from '../json/html-tags-void.json' with { type: 'json' }; -export const unifiedTagCollection = [...htmlTags, ...htmlVoidTags]; +const browser = bowser.getParser(window.navigator.userAgent).getBrowser(); + +export let unifiedTagCollection = []; + +if (browser === "Chrome") { + unifiedTagCollection = [...htmlTags, ...htmlVoidTags]; +} else if (browser === "Firefox") { + const htmlTags = await fetchMultipleJsonUrls([ + `${window.location.origin}/json/html-tags.json`, + `${window.location.origin}/json/html-tags-void.json` + ]); + + unifiedTagCollection = [...htmlTags]; +} else { + unifiedTagCollection = [...htmlTags, ...htmlVoidTags]; +} export default function isValidTag(tag) { return unifiedTagCollection.includes(tag); +} + +/** @returns {Promise} */ +async function fetchMultipleJsonUrls(urls) { + const responses = await Promise.all(urls.map(url => fetch(url))); + const jsonArrays = await Promise.all(responses.map(response => response.json())); + return jsonArrays.flat(); } \ No newline at end of file