summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorumbrae <umbrae@d4e419ec-0920-11de-bbfd-a7c1bc4c261e>2009-03-10 14:56:38 +0000
committerumbrae <umbrae@d4e419ec-0920-11de-bbfd-a7c1bc4c261e>2009-03-10 14:56:38 +0000
commit2708262e43866c1e2ecb233de6631a4e760fa039 (patch)
tree6110b63bdb9a44027600f086bea845438f52d88e
parentd0743842804a6a8b853d45d81082f3c50f4d8fef (diff)
downloadreadability-simple-2708262e43866c1e2ecb233de6631a4e760fa039.tar.bz2
readability-simple-2708262e43866c1e2ecb233de6631a4e760fa039.zip
Some tweaks in case of epic fail.
git-svn-id: http://arc90labs-readability.googlecode.com/svn/trunk@18 d4e419ec-0920-11de-bbfd-a7c1bc4c261e
-rwxr-xr-xjs/readability.js15
1 files 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 <a href="http://code.google.com/p/arc90labs-readability/issues/entry">let us know by submitting an issue.</a>';
+ }
// 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 ) {