feat: BNF/Strasbourg special cases — GM API adaptation#8
Merged
Conversation
mediapart (BNF + Strasbourg), arretsurimages (BNF), alternatives-economiques (BNF) were injected verbatim from the ophirofox extension, using chrome.storage.sync and configurationsSpecifiques() — both unavailable in a userscript context. Replaced with adapted heredoc blocks: - chrome.storage.sync → GM.getValue/GM.setValue/GM.deleteValue - configurationsSpecifiques() → getOphirofoxConfig() + AUTH_URL_* property check - Preserved SPA navigation hooks for arretsurimages - Preserved MutationObserver for alternatives-economiques paywall iframe
Instead of hardcoding adapted copies of the ophirofox JS files, read them from the original source and pipe through a Python transformer that replaces: - chrome.storage.sync.get/set/remove → GM.getValue/setValue/deleteValue - configurationsSpecifiques([...]) → getOphirofoxConfig() + AUTH_URL_* check This means any upstream fix to the ophirofox source files automatically propagates to the userscript on next generation. Sites covered: mediapart (BNF+Strasbourg), arretsurimages (BNF), alternatives-economiques (BNF), pressreader (BNF)
The generate-userscript.sh now depends on adapt-special-case.py for transforming chrome.* APIs to GM.* equivalents in special-case sites. The workflow must copy both files into the ophirofox working directory.
chrome.storage.sync.set() and remove() are sometimes called without await (fire-and-forget in non-async functions like tryInject). The transformer now captures whether await was present and only outputs await if it was.
The pasteStyle function was blindly appending !important to every CSS rule. CSS from ophirofox content scripts (e.g. arret-sur-images, alternatives-economiques) already declares !important on some properties, producing broken CSS like: padding: 0.5em !important !important; Fixed regex: /(?:\s*!important)?;/g — only adds !important if not already present.
… links Each site's createLink now wraps the returned element with ophirofoxWrapWithCog(), which adds a settings gear button on iOS/macOS — same pattern as the existing 'Lire sur Europresse' link in CONFIG_FUNCTIONS_BLOCK.
Changed the settings gear (⚙) button from transparent to white background and added z-index:20 so it stays above page content on all sites.
6382f71 to
94c6cc4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The `generate-userscript.sh` script was blindly copying content_script JS files into the userscript. Four sites use `chrome.storage.sync` and/or `configurationsSpecifiques()` — APIs that don't exist in a userscript context. The "Lire avec BNF" / "Lire avec Strasbourg" links silently failed.
Solution
Created `adapt-special-case.py` — a Python transformer that reads original ophirofox JS files and outputs GM-adapted versions. The bash script pipes the four special files through it during generation.
Sites covered
Why a transformer instead of heredoc blocks?
Any upstream fix to the ophirofox source files automatically flows into the userscript on next generation. No manual sync needed.
Verification
```
$ grep -c 'chrome.' test-output.js # 0
$ grep -c 'configurationsSpecifiques' test-output.js # 0
$ grep -c 'GM.' test-output.js # 72
```