Fetch CSS files that can't be accessed directly #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #18, #16, #14, #10, #8.
Context
When investigating #18, I found that CSS files that are linked linked with
rel="preload"
, didn't appear to have their font-family overrides correctly added to the#country-flag-fixer-ext
style tag that the extension adds. For example:In particular, I found the script failed at line 25 of
content.js
, and debugging in dev tools, it looks like theserel="preload"
css files for whatever reason don't let you usesheet.cssRules
(like line 25 uses).So I added in a try/catch (here) that first tries to read the rules with
sheet.cssRules
, and if this fails, then it will try to retrieve the CSS file directly from the href (new functionfetchCSSRulesFromUrl
).This is the core of the change which gets the missed styles added into the
#country-flag-fixer-ext
style tag.Other changes done alongside this change:
#country-flag-fixer-ext
tag is updated:#country-flag-fixer-ext
tag, its existingcssRules
are read, added to the new tag, and then the new CSS rules are added#country-flag-fixer-ext
, but then if there was a CORS or some other error trying to read a later CSS file, this would error and exit the whole process meaning the rules from the previously successfully read file wouldn't be addedupdateFontFamilyRules()
instead ofapplyCustomFontStyles()
styleSheetsChanged
into its own functionTesting
This fix works for nearly all the broken sites mentioned in current issues except Bluesky.
Checked against the following URLs. Screenshots below.
Quizlet ✅
Strava ✅
Letterboxed ✅
Old reddit ✅
Bluesky ❌
Emojipedia ✅