@@ -2,6 +2,15 @@ var __init;
22__init ( ) ;
33
44__init = function ( ) {
5+ function argsFromHash ( hash ) {
6+ const index = hash . indexOf ( "?" ) ;
7+ if ( index >= 0 ) {
8+ return new URLSearchParams ( hash . slice ( index + 1 ) ) ;
9+ }
10+
11+ return new URLSearchParams ( ) ;
12+ }
13+
514 let timer ;
615 const list = [ ] ;
716 function scrolling ( _ , delay = 300 ) {
@@ -47,8 +56,7 @@ __init = function() {
4756 }
4857
4958 function scrollToPart ( ) {
50- const hash = location . hash . replace ( / .* \? / , "" ) ;
51- const args = new URLSearchParams ( hash ) ;
59+ const args = argsFromHash ( location . hash ) ;
5260 const id = args . get ( "id" ) || "_top" ;
5361 const target = document . getElementById ( id ) ;
5462 const scroller = document . querySelector ( ".content" ) ;
@@ -250,18 +258,15 @@ __init = function() {
250258 }
251259
252260 function fixLinks ( ) {
253- const root = new URL ( location . href ) ;
254- root . hash = "" ;
255-
261+ const root = "" + new URL ( "./" , location . href ) ;
256262 for ( const a of document . querySelectorAll ( "a" ) ) {
257263 const url = new URL ( a . href ) ;
258- const hash = url . hash . replace ( / .* \? / , "" ) ;
259- const args = new URLSearchParams ( hash ) ;
260- url . hash = "" ;
264+ const args = argsFromHash ( url . hash ) ;
265+ url . search = url . hash = "" ;
261266
262- if ( root . href === url . href ) {
267+ if ( url . href . startsWith ( root ) ) {
263268 args . delete ( "id" ) ;
264-
269+
265270 if ( args . size ) {
266271 a . href = "?" + args ;
267272 }
0 commit comments