Open anoved opened 1 year ago
Yoinked from the og readability:
/**
* For easier reading, convert this document to have footnotes at the bottom rather than inline links.
* @see http://www.roughtype.com/archives/2010/05/experiments_in.php
*
* @return void
**/
addFootnotes: function(articleContent) {
var footnotesWrapper = document.getElementById('readability-footnotes'),
articleFootnotes = document.getElementById('readability-footnotes-list');
if(!footnotesWrapper) {
footnotesWrapper = document.createElement("DIV");
footnotesWrapper.id = 'readability-footnotes';
footnotesWrapper.innerHTML = '<h3>References</h3>';
footnotesWrapper.style.display = 'none'; /* Until we know we have footnotes, don't show the references block. */
articleFootnotes = document.createElement('ol');
articleFootnotes.id = 'readability-footnotes-list';
footnotesWrapper.appendChild(articleFootnotes);
var readFooter = document.getElementById('readFooter');
if(readFooter) {
readFooter.parentNode.insertBefore(footnotesWrapper, readFooter);
}
}
var articleLinks = articleContent.getElementsByTagName('a');
var linkCount = articleFootnotes.getElementsByTagName('li').length;
for (var i = 0; i < articleLinks.length; i++)
{
var articleLink = articleLinks[i],
footnoteLink = articleLink.cloneNode(true),
refLink = document.createElement('a'),
footnote = document.createElement('li'),
linkDomain = footnoteLink.host ? footnoteLink.host : document.location.host,
linkText = readability.getInnerText(articleLink);
if(articleLink.className && articleLink.className.indexOf('readability-DoNotFootnote') !== -1 || linkText.match(readability.regexps.skipFootnoteLink)) {
continue;
}
linkCount++;
/** Add a superscript reference after the article link */
refLink.href = '#readabilityFootnoteLink-' + linkCount;
refLink.innerHTML = '<small><sup>[' + linkCount + ']</sup></small>';
refLink.className = 'readability-DoNotFootnote';
try { refLink.style.color = 'inherit'; } catch(e) {} /* IE7 doesn't like inherit. */
if(articleLink.parentNode.lastChild == articleLink) {
articleLink.parentNode.appendChild(refLink);
} else {
articleLink.parentNode.insertBefore(refLink, articleLink.nextSibling);
}
articleLink.name = 'readabilityLink-' + linkCount;
try { articleLink.style.color = 'inherit'; } catch(e) {} /* IE7 doesn't like inherit. */
footnote.innerHTML = "<small><sup><a href='#readabilityLink-" + linkCount + "' title='Jump to Link in Article'>^</a></sup></small> ";
footnoteLink.innerHTML = (footnoteLink.title ? footnoteLink.title : linkText);
footnoteLink.name = 'readabilityFootnoteLink-' + linkCount;
footnote.appendChild(footnoteLink);
footnote.innerHTML = footnote.innerHTML + "<small> (" + linkDomain + ")</small>";
articleFootnotes.appendChild(footnote);
}
if(linkCount > 0) {
footnotesWrapper.style.display = 'block';
}
},
This was a feature in McReadability and the original arc90 bookmarklet. Suitable for printing.