Created
January 21, 2019 19:54
-
-
Save nkgokul/2690b1c7a11c6a9de5d177ae11bcf293 to your computer and use it in GitHub Desktop.
Generate TOC for published medium articles
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
getTOCHtml(); | |
function getTOCHtml() { | |
let TOCHtml = "" | |
$$("h2,h3,h4,h5").forEach(function(ele){ | |
TOCHtml += `<a href='#${ele.id}'>${ele.innerText}</a><br/>` ; | |
//console.log(ele.innerText); | |
}) | |
//console.log(TOCHtml); | |
var parentElement = $('.postArticle-content'); | |
// Get a reference to the first child | |
var theFirstChild = parentElement.firstChild; | |
// Create a new element | |
var newElement = document.createElement("div"); | |
newElement.innerHTML = TOCHtml | |
// Insert the new element before the first child | |
parentElement.insertBefore(newElement, theFirstChild); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment