From 260ec29c3adfff8157cd8176ef05c09bda2b253f Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 3 Nov 2010 18:35:20 +0000 Subject: Updated TODO, added bug with bookmarklet in ff --- BUGS | 3 +++ TODO | 3 ++- readable.js | 34 ++++++++++++++++++---------------- webheader.html | 4 ++-- 4 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 BUGS diff --git a/BUGS b/BUGS new file mode 100644 index 0000000..52d3f62 --- /dev/null +++ b/BUGS @@ -0,0 +1,3 @@ +When run as a bookmarklet in firefox, the first run it hasn't registered +readable() by the time it is called. Subsequent runs work fine. This +occurs whether readable is in a separate javascript: clause or not. diff --git a/TODO b/TODO index 1fe5772..fbc17fe 100644 --- a/TODO +++ b/TODO @@ -1,2 +1,3 @@ -chrome extension +chromium extension http://code.google.com/chrome/extensions/index.html +epiphany extension http://projects.gnome.org/epiphany/extensions make tests, which process sample html files and check the output diff --git a/readable.js b/readable.js index 6e6a489..726f522 100755 --- a/readable.js +++ b/readable.js @@ -4,7 +4,7 @@ * See COPYING file for copyright, license and warranty details. */ -if(document.readable_original === undefined) document.readable_original = false; +if(window.content.document.readable_original === undefined) window.content.document.readable_original = false; function readable() { @@ -20,27 +20,29 @@ function readable() return n; } - /* if we're running from a browser extension, rather than a page */ - if(document == undefined) - document = window.content.document; + var doc; + if(document.body === undefined) + doc = window.content.document; + else + doc = document; /* if readable_original is set, then the readable version is currently active, * so switch to the readable_original html */ - if (document.readable_original) { - document.body.innerHTML = document.readable_original; - for (var i = 0; i < document.styleSheets.length; i++) - document.styleSheets[i].disabled = false; - document.readable_original = false + if (doc.readable_original) { + doc.body.innerHTML = doc.readable_original; + for (var i = 0; i < doc.styleSheets.length; i++) + doc.styleSheets[i].disabled = false; + doc.readable_original = false return 0; } - document.readable_original = document.body.innerHTML; + doc.readable_original = doc.body.innerHTML; var biggest_num = 0; var biggest_tag; /* search for tag with most direct children

tags */ - var t = document.getElementsByTagName("*"); + var t = doc.getElementsByTagName("*"); for (var i = 0; i < t.length; i++) { var p_num = count_p(t[i]); if (p_num > biggest_num) { @@ -55,18 +57,18 @@ function readable() } /* save and sanitise content of chosen tag */ - var fresh = document.createElement("div"); + var fresh = doc.createElement("div"); fresh.innerHTML = biggest_tag.innerHTML; fresh.innerHTML = fresh.innerHTML.replace(/<\/?font[^>]*>/g, ""); fresh.innerHTML = fresh.innerHTML.replace(/style="[^"]*"/g, ""); fresh.innerHTML = fresh.innerHTML.replace(/<\/?a[^>]*>/g, ""); - for (var i = 0; i < document.styleSheets.length; i++) - document.styleSheets[i].disabled = true; + for (var i = 0; i < doc.styleSheets.length; i++) + doc.styleSheets[i].disabled = true; - document.body.innerHTML = + doc.body.innerHTML = "

" + - "

" + document.title + "

" + + "

" + doc.title + "

" + fresh.innerHTML + "
"; return 0; diff --git a/webheader.html b/webheader.html index 1c615af..b7891cc 100644 --- a/webheader.html +++ b/webheader.html @@ -1,10 +1,10 @@