This repository was archived by the owner on Jun 7, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -284,15 +284,27 @@ window.addEventListener("load", function () {
284284 e . stopPropagation ( ) ;
285285 } ) ;
286286 } ) ;
287-
287+
288+ // re-write some urls
289+ // This is tricker than it looks and you have to obey the rules for # anchors
290+ // The #anchors must come after the query string as the server basically ignores any part
291+ // of a url that comes after # - like a comment...
288292 if ( location . href . includes ( "mode=browsing" ) ) {
289293 let queryString = "?mode=browsing" ;
290294 document . querySelectorAll ( "a" ) . forEach ( ( link ) => {
291- if ( link . href . includes ( "books/published" ) ) {
295+ console . log ( `Starting: ${ link . href } ` )
296+ let anchorText = "" ;
297+ if ( link . href . includes ( "books/published" ) && ! link . href . includes ( "?mode=browsing" ) ) {
298+ if ( link . href . includes ( "#" ) ) {
299+ let aPoint = link . href . indexOf ( "#" ) ;
300+ anchorText = link . href . substring ( aPoint ) ;
301+ link . href = link . href . substring ( 0 , aPoint ) ;
302+ }
292303 link . href = link . href . includes ( "?" )
293- ? link . href + queryString . replace ( "?" , "&" )
294- : link . href + queryString ;
304+ ? link . href + queryString . replace ( "?" , "&" ) + anchorText
305+ : link . href + queryString + anchorText ;
295306 }
307+ console . log ( `Ending: ${ link . href } ` )
296308 } ) ;
297309 }
298310} ) ;
You can’t perform that action at this time.
0 commit comments