@@ -265,7 +265,13 @@ function timeTravel(hash, path = 'index.html') {
265265 return response . text ( ) ;
266266 } )
267267 . then ( html => {
268- // Skip HTML rewriting entirely and just inject the fetch interceptor directly
268+ // Add base tag without complex HTML parsing
269+ const baseUrl = `https://raw.githubusercontent.com/TobiasMue91/tobiasmue91.github.io/${ hash } /` ;
270+ const baseTag = `<base href="${ baseUrl } ">` ;
271+
272+ // Insert the base tag at the beginning of the head (simple string replace)
273+ html = html . replace ( / < h e a d > / i, `<head>${ baseTag } ` ) ;
274+
269275 currentHash = hash ;
270276
271277 if ( contentFrame ) {
@@ -291,32 +297,36 @@ function timeTravel(hash, path = 'index.html') {
291297 frameDoc . open ( ) ;
292298 frameDoc . write ( html ) ;
293299
294- // Inject the fetch interceptor script without modifying anything else
300+ // This is the same fetch interceptor that worked before
295301 const script = frameDoc . createElement ( 'script' ) ;
296- script . textContent = `
297- // Intercept fetch for JSON files only
298- const originalFetch = window.fetch;
299- window.fetch = function(url, options) {
300- if (typeof url === 'string') {
301- if (url.includes('data/games.json') || url.includes('data/tools.json')) {
302- const fileName = url.split('/').pop();
303- const absoluteUrl = "https://raw.githubusercontent.com/TobiasMue91/tobiasmue91.github.io/${ hash } /data/" + fileName;
304- console.log("Rewriting fetch URL:", url, "to", absoluteUrl);
305- return originalFetch(absoluteUrl, options);
306- }
307- }
308- return originalFetch(url, options);
309- };
310- console.log("Fetch interceptor installed for JSON files");
311- ` ;
302+ script . textContent =
303+ "// Remove problematic scripts\n" +
304+ "const scriptsToRemove = ['timeline.js', 'sw.js', 'chatbot.js', 'gc.zgo.at/count.js'];\n" +
305+ "document.querySelectorAll('script').forEach(script => {\n" +
306+ " const src = script.getAttribute('src');\n" +
307+ " if (src && scriptsToRemove.some(name => src.includes(name))) {\n" +
308+ " script.remove();\n" +
309+ " }\n" +
310+ "});\n" +
311+ "\n" +
312+ "// Intercept fetch for JSON files\n" +
313+ "const originalFetch = window.fetch;\n" +
314+ "window.fetch = function(url, options) {\n" +
315+ " if (typeof url === 'string') {\n" +
316+ " if (url.includes('data/games.json') || url.includes('data/tools.json')) {\n" +
317+ " const fileName = url.split('/').pop();\n" +
318+ " const absoluteUrl = '" + baseUrl + "data/' + fileName;\n" +
319+ " console.log('Rewriting fetch URL:', url, 'to', absoluteUrl);\n" +
320+ " return originalFetch(absoluteUrl, options);\n" +
321+ " }\n" +
322+ " }\n" +
323+ " return originalFetch(url, options);\n" +
324+ "};" ;
312325 frameDoc . head . appendChild ( script ) ;
313326
314- // Close the document after adding the script
315327 frameDoc . close ( ) ;
316328
317- // Set up link interception
318329 setTimeout ( ( ) => interceptLinks ( frameDoc , hash ) , 300 ) ;
319-
320330 document . querySelector ( '#timeline-container' ) . scrollLeft = timelineScrollPosition ;
321331 hideLoading ( ) ;
322332 } )
0 commit comments