Skip to content

Instantly share code, notes, and snippets.

@bgrins
Last active October 13, 2015 04:47
Show Gist options
  • Save bgrins/4141504 to your computer and use it in GitHub Desktop.
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.
// 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