MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / updateRoute

Function updateRoute

src/common/router.js:12–34  ·  view source on GitHub ↗
(noConfirm)

Source from the content-addressed store, hash-verified

10updateRoute();
11
12function updateRoute(noConfirm) {
13 const hash = window.location.hash.slice(1);
14 if (noConfirm || !route.confirmChange) {
15 const [pathname, search = ''] = hash.split('?');
16 /**
17 * @typedef {Object} VMRoute
18 * @prop {string} hash - entire hash without # e.g. 'path/name?foo=1&bar=2'
19 * @prop {string} pathname - 'path/name'
20 * @prop {string[]} paths - ['path', 'name']
21 * @prop {StringMap} query - {foo: '1', bar: '2'}
22 */
23 Object.assign(route, {
24 hash,
25 pathname,
26 paths: pathname.split('/'),
27 query: loadQuery(search),
28 });
29 } else if (route.hash !== hash) {
30 // restore the pinned route
31 setRoute(route.hash, false, true);
32 route.confirmChange(hash);
33 }
34}
35
36// popstate should be the first to ensure hashchange listeners see the correct lastRoute
37addEventListener('popstate', () => stack.pop());

Callers 2

router.jsFile · 0.85
setRouteFunction · 0.85

Calls 2

loadQueryFunction · 0.90
setRouteFunction · 0.85

Tested by

no test coverage detected