Last active
October 13, 2015 04:47
-
-
Save bgrins/4141504 to your computer and use it in GitHub Desktop.
JS function to copy notes from essays into the title attributes of their links. Can run this straight from the console or add it as a devtools snippet.
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
// For instance: http://paulgraham.com/growth.html | |
// Copy the following into devtools console, then you should see note contents when hovering the link | |
[].forEach.call(document.querySelectorAll("a[href*='#f']"), function(l) { | |
var to = document.querySelector('[name=' + l.href.split('#')[1] + ']'); | |
var text = ''; | |
while ((to = to.nextSibling) && to.tagName !== "A") { | |
text+= to.textContent.replace(/\n/g, ' ') + '\n'; | |
} | |
text = text.replace(/^\s*\]\s*/, '').replace(/\s*\[\s*/, '').replace(/\n{2,}/g, '\n\n'); | |
l.setAttribute('title', text); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment