@violentmonkey/url
v0.1.0
Published
Add SPA support to your userscript.
Downloads
15
Readme
@violentmonkey/url
Add SPA support to your userscript.
Usage
Importing
Use in a userscript:
// ... // @require https://cdn.jsdelivr.net/npm/@violentmonkey/url // ... const { onNavigate } = VM;
Use as a module:
$ yarn add @violentmonkey/url
import { onNavigate } from '@violentmonkey/url';
Handling
function handleNavigate() {
resetAllFeatures();
if (window.location.pathname === '/foo') {
enableFeatureFoo();
} else if (window.location.pathname === '/bar') {
enableFeatureBar();
}
}
// Watch route change
VM.onNavigate(handleNavigate);
// Call it once for the initial state
handleNavigate();