From 2708262e43866c1e2ecb233de6631a4e760fa039 Mon Sep 17 00:00:00 2001 From: umbrae Date: Tue, 10 Mar 2009 14:56:38 +0000 Subject: Some tweaks in case of epic fail. git-svn-id: http://arc90labs-readability.googlecode.com/svn/trunk@18 d4e419ec-0920-11de-bbfd-a7c1bc4c261e --- js/readability.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/js/readability.js b/js/readability.js index 1c92e3f..6477b35 100755 --- a/js/readability.js +++ b/js/readability.js @@ -81,6 +81,12 @@ function grabArticle() { for(nodeIndex = 0; (node = document.getElementsByTagName('*')[nodeIndex]); nodeIndex++) if(typeof node.readability != 'undefined' && (topDiv == null || node.readability.contentScore > topDiv.readability.contentScore)) topDiv = node; + + if(topDiv == null) + { + topDiv = document.createElement('div'); + topDiv.innerHTML = 'Sorry, readability was unable to parse this page for content. If you feel like it should have been able to, please let us know by submitting an issue.'; + } // REMOVES ALL STYLESHEETS ... for (var k=0;k < document.styleSheets.length; k++) @@ -134,8 +140,13 @@ function cleanStyles( e ) { e = e || document; var cur = e.firstChild; - // Remove any root styles - e.removeAttribute('style'); + // If we had a bad node, there's not much we can do. + if(!e) + return; + + // Remove any root styles, if we're able. + if(typeof e.removeAttribute == 'function') + e.removeAttribute('style'); // Go until there are no more child nodes while ( cur != null ) { -- cgit v1.2.3