Skip to content

feat: BNF/Strasbourg special cases — GM API adaptation#8

Merged
Write merged 7 commits into
mainfrom
feature/special-cases-bnf-strasbourg
Jun 20, 2026
Merged

feat: BNF/Strasbourg special cases — GM API adaptation#8
Write merged 7 commits into
mainfrom
feature/special-cases-bnf-strasbourg

Conversation

@Write

@Write Write commented Jun 20, 2026

Copy link
Copy Markdown
Owner

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.

API Before (broken) After (works)
Storage `chrome.storage.sync.get/set/remove` `GM.getValue/setValue/deleteValue`
Partner check `configurationsSpecifiques([...])` `getOphirofoxConfig()` + `AUTH_URL_*` property check

Sites covered

  • mediapart — BNF + Bibliothèque universitaire de Strasbourg
  • arretsurimages — BNF (SPA navigation hooks preserved)
  • alternatives-economiques — BNF (MutationObserver for paywall iframe)
  • pressreader — BNF (simple link injection)

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
```

Write added 7 commits June 20, 2026 19:47
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.
@Write Write force-pushed the feature/special-cases-bnf-strasbourg branch from 6382f71 to 94c6cc4 Compare June 20, 2026 22:44
@Write Write merged commit 406f0d1 into main Jun 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant