From a7b81d3999043cf2023538700df620aaf01a3876 Mon Sep 17 00:00:00 2001 From: umbrae Date: Tue, 10 Mar 2009 18:37:05 +0000 Subject: some footer tweaks git-svn-id: http://arc90labs-readability.googlecode.com/svn/trunk@19 d4e419ec-0920-11de-bbfd-a7c1bc4c261e --- js/readability.js | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/js/readability.js b/js/readability.js index 6477b35..8b14f95 100755 --- a/js/readability.js +++ b/js/readability.js @@ -1,9 +1,13 @@ +var readabilityVersion = "0.3"; + (function(){ var objOverlay = document.createElement("div"); var objinnerDiv = document.createElement("div"); objOverlay.id = "readOverlay"; objinnerDiv.id = "readInner"; + + document.body.readability = {"contentScore": 0, originalHTML: document.body.innerHTML.toString()}; // Apply user-selected styling: document.body.className = readStyle; @@ -19,15 +23,27 @@ body = document.createElement("body"); document.body = body; } - - // This removes everything else on the page. Requires a page refresh to undo it. - // I tried the damn overlay on top - but had rendering issues: + document.body.innerHTML = ""; // Inserts the new content : document.body.insertBefore(objOverlay, document.body.firstChild); })() +function restoreDocument() { + document.body.innerHTML = document.body.readability.originalHTML; + for (var k=0;k < document.styleSheets.length; k++) + if (document.styleSheets[k].href != null) + document.styleSheets[k].disabled = (document.styleSheets[k].href.lastIndexOf("readability") != -1); + + // Enable all style tags in head: + var styleTags = document.getElementsByTagName("style"); + for (var j=0;j < styleTags.length; j++) + styleTags[j].disabled = false; + + return false; +} + function grabArticle() { var allParagraphs = document.getElementsByTagName("p"); var topDivCount = 0; @@ -57,13 +73,13 @@ function grabArticle() { parentNode.readability = {"contentScore": 0}; // Look for a special classname - if(parentNode.className.match(/(comment|meta)/)) + if(parentNode.className.match(/(comment|meta|footer|footnote)/)) parentNode.readability.contentScore -= 50; else if(parentNode.className.match(/(hentry|entry[-]?(content|text|body)|article[-]?(content|text|body))/)) parentNode.readability.contentScore += 25; // Look for a special ID - if(parentNode.id.match(/(comment|meta)/)) + if(parentNode.id.match(/(comment|meta|footer|footnote)/)) parentNode.readability.contentScore -= 50; else if(parentNode.id.match(/(hentry|entry[-]?(content|text)|article[-]?(text|content))/)) parentNode.readability.contentScore += 25; @@ -96,8 +112,10 @@ function grabArticle() { // Remove all style tags in head (not doing this on IE) : var styleTags = document.getElementsByTagName("style"); for (var j=0;j < styleTags.length; j++) - if (navigator.appName != "Microsoft Internet Explorer") - styleTags[j].textContent = ""; + styleTags[j].disabled = true; +// if (navigator.appName != "Microsoft Internet Explorer") +// styleTags[j].textContent = ""; + cleanStyles(topDiv); // Removes all style attributes topDiv = killDivs(topDiv); // Goes in and removes DIV's that have more non

stuff than

stuff @@ -113,7 +131,13 @@ function grabArticle() { // Add the footer and contents: articleFooter.id = "readFooter"; - articleFooter.innerHTML = ""; + articleFooter.innerHTML = "\ + \ +

\ + Back to Original
\ + v" + readabilityVersion + "  &bull  Report an Issue\ +
\ + "; articleContent.appendChild(topDiv); articleContent.appendChild(articleFooter); -- cgit v1.2.3