mirror of
https://github.com/thegeneralist01/archivr
synced 2026-07-22 03:05:32 +02:00
fix: dispatch single-file-user-script-init so request hook fires
single-file's initUserScriptHandler (in single-file-bootstrap.js) listens for 'single-file-user-script-init' and only then installs _singleFile_waitForUserScript. Without that dispatch our scripts' 'single-file-on-before-capture-request' listeners were never reached, so neither strip-scripts nor reader-mode Readability applied. Dispatch the init event at the top of strip-scripts (always present) and redundantly in READER_MODE_SCRIPT. Verified end-to-end: artifact for run_b3181d6d276e4e56a1a6c356ef9bbe8f has meta content="applied", max-width:680px CSS, 0 script tags.
This commit is contained in:
parent
39c5800ff5
commit
a6ca24b846
1 changed files with 10 additions and 4 deletions
|
|
@ -85,6 +85,9 @@ const READER_MODE_SCRIPT: &str = concat!(
|
|||
_archivrReaderMark('failed:exception:' + (e && e.message ? e.message : String(e)));
|
||||
}
|
||||
}
|
||||
// Ensure _singleFile_waitForUserScript is installed (strip-scripts also does
|
||||
// this, but be explicit here in case reader-mode ever runs without it).
|
||||
dispatchEvent(new CustomEvent('single-file-user-script-init'));
|
||||
// Synchronous work — no preventDefault()/response dispatch needed.
|
||||
addEventListener('single-file-on-before-capture-request', _archivrApplyReader);
|
||||
})();
|
||||
|
|
@ -217,10 +220,13 @@ fn save_with(
|
|||
let strip_scripts_path = temp_dir.join("sf-strip-scripts.js");
|
||||
std::fs::write(
|
||||
&strip_scripts_path,
|
||||
"addEventListener('single-file-on-before-capture-request',()=>{\
|
||||
document.querySelectorAll('script:not([type=\"application/ld+json\"])')\
|
||||
.forEach(el=>el.remove());\
|
||||
});",
|
||||
// Dispatch single-file-user-script-init so single-file installs
|
||||
// _singleFile_waitForUserScript, which gates the -request hooks.
|
||||
"dispatchEvent(new CustomEvent('single-file-user-script-init'));\
|
||||
addEventListener('single-file-on-before-capture-request',()=>{\
|
||||
document.querySelectorAll('script:not([type=\"application/ld+json\"])')\
|
||||
.forEach(el=>el.remove());\
|
||||
});",
|
||||
)
|
||||
.context("failed to write single-file user script")?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue