<html> <head> <style> /* Make all links look active even when href isn't set. We do this so we can set the onclick attribute instead. */ a { color: #0000EE; text-decoration: underline; cursor: pointer; } a:visited { color: #551A8B; text-decoration: underline; cursor: pointer; } </style> </head> <body> <div id="content"> </div> <script> /* Lukas quickly coded the stuff below. Use at your own risk.... // // This script fakes links to local webpages by replacing instances of href="/pageName.html" with onclick="load(pageName);" // The load(pageName) function replaces content from one webpage with content from another. // // OG pages copied from Course Builder // Example: { 'index.html': '<h1>Hello, World!</h1>' } */ let pageBodies = { 'index.html': '<h3>Fret-it</h3> <h4>Has the prime minister met with aliens?</h4> <p>After a series of chirps on Chirper, the prime minster confirmed that he has indeed visited the famour airforce base Zone 15.</p> <h3>Other communities you might like</h3> <ul> <a href="/aliens.html">Aliens</a> <a href="/e-tea.html">E-Tea </a> </ul>',
'aliens.html': '<a href="/index.html">Home</a> <h3>Alieeens Dude</h3> <p>Subscribe to the Aliens Dude newsletter to get all your favorite alien memes.</p>',
'e-tea.html': '<a href="/index.html">Home</a> <h3>Buy some E-tea!</h3> <p>Order some out of this world tea, E-tea!</p>',
'ufo.html': '<a href="/index.html">home</a> <h3>UFOs</h3> <p>A place where you can share all of your UFO sightings</p>', }; /* // Create a pathToOnClickMapping object where keys are href absolute paths and values are onclick attributes replacing the page's body // Example: { 'href="/trail.html"': 'load(\'trail.html\');' } */ let pathToOnClickMapping = {}; Object.keys(pageBodies).forEach((key) => { pathToOnClickMapping['href="/' + key + '"'] = 'onclick="load(\'' + key + '\');"'; }); let regex = new RegExp(Object.keys(pathToOnClickMapping).join("|"), "gi"); /* // Create a pagesWithAbsolutePathsReplaced object that stores webpage bodies with absolute paths replaced with onclick=load(pageName) */ let pagesWithAbsolutePathsReplaced = {}; Object.keys(pageBodies).forEach((key) => { pagesWithAbsolutePathsReplaced[key] = pageBodies[key].replace(regex, function(matched) { return pathToOnClickMapping[matched]; }); }); /* // Replace content of webpage with page from pagesWithAbsolutePathsReplaced */ function load(pageName) { document.getElementById('content').innerHTML = pagesWithAbsolutePathsReplaced[pageName]; }; load('index.html'); </script> </body> </html>]]>