Last active
March 21, 2021 19:13
-
-
Save joehonton/88231590e645d8dfdf49d9cc8eece227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const articleUrls = [ | |
'/feb-28-2021.html', | |
'/feb-21-2021.html', | |
'/feb-14-2021.html', | |
'/feb-07-2021.html' | |
]; | |
const nextIndex = 0; | |
async fetchNextArticle() { | |
// fetch the article using HTTP | |
const response = await fetch(articleUrls[nextIndex++]); | |
if (response.status != 200 && response.status != 304) | |
return; | |
const templateText = await response.text(); | |
// get the <body> of the article's HTML | |
const template = document.createElement('template'); | |
template.innerHTML = templateText; | |
const body = template.content.querySelector('body'); | |
// create a new <article> and insert it | |
const nextArticle = document.createElement('article') | |
nextArticle.innerHTML = body.innerHTML; | |
bottomOfPage.parentNode.insertBefore(nextArticle, bottomOfPage); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment