120120 window . location . replace ( newPath + url . search + url . hash ) ;
121121 }
122122 }
123- } ) ( ) ;
124-
125- //Repair all broken urls as of now.
126-
127- ( function ( ) {
128- const is404 =
129- document . title . includes ( "Page not found" ) ||
130- document . body . textContent . includes ( "could not be found" ) ;
131-
132- if ( ! is404 ) {
133- sessionStorage . removeItem ( "alreadyRedirected" ) ;
134- return ;
135- }
136-
137- console . warn ( "Detected 404 page" ) ;
138-
139- // Only redirect once
140- if ( sessionStorage . getItem ( "alreadyRedirected" ) === "true" ) {
141- console . log ( "Skipping redirect" ) ;
142- return ;
143- }
144-
145- setTimeout ( ( ) => {
146- const segments = window . location . pathname . split ( "/" ) . filter ( Boolean ) ;
147- const base = segments [ 0 ] ;
148- const rem = segments . slice ( 1 ) ;
149-
150- // 2) Generic duplicate: Y/X/X/... → Y/X/...
151- if ( rem . length >= 2 && rem [ 0 ] === rem [ 1 ] ) {
152- const x = rem [ 0 ] ;
153- const rest = rem . slice ( 2 ) . join ( "/" ) ;
154- const newPath = `/${ base } /${ x } /${ rest } ` ;
155- console . log ( `🔁 Redirecting (generic dup): ${ newPath } ` ) ;
156- sessionStorage . setItem ( "alreadyRedirected" , "true" ) ;
157- return window . location . replace ( newPath + location . search + location . hash ) ;
158- }
159-
160- // 3) Y/course/X/X/... → Y/X/...
161- if ( rem . length >= 3 && rem [ 0 ] === "course" && rem [ 1 ] === rem [ 2 ] ) {
162- const x = rem [ 1 ] ;
163- const rest = rem . slice ( 3 ) . join ( "/" ) ;
164- const newPath = `/${ base } /${ x } /${ rest } ` ;
165- console . log ( `🔁 Redirecting (course dup): ${ newPath } ` ) ;
166- sessionStorage . setItem ( "alreadyRedirected" , "true" ) ;
167- return window . location . replace ( newPath + location . search + location . hash ) ;
168- }
169-
170- // 4)
171- if ( rem . length >= 2 ) {
172- const x = rem [ 1 ] ;
173- const rest = rem . slice ( 2 ) . join ( "/" ) ;
174- const newPath = `/${ base } /${ x } /${ rest } ` ;
175- console . log ( `🔁 Redirecting (bad-middle): ${ newPath } ` ) ;
176- sessionStorage . setItem ( "alreadyRedirected" , "true" ) ;
177- return window . location . replace ( newPath + location . search + location . hash ) ;
178- }
179-
180- } , 62.5 ) ;
181- } ) ( ) ;
123+ } ) ( ) ;
0 commit comments