diff options
author | Nick White <git@njw.me.uk> | 2010-11-03 18:35:20 +0000 |
---|---|---|
committer | Nick White <git@njw.me.uk> | 2010-11-03 18:35:20 +0000 |
commit | 260ec29c3adfff8157cd8176ef05c09bda2b253f (patch) | |
tree | 9706b9f1cafd309c0dc42930be672fbcdcec49eb | |
parent | f0ee8dc6fcb45ffc3b3b00e410cc267dac6e7427 (diff) |
Updated TODO, added bug with bookmarklet in ff
-rw-r--r-- | BUGS | 3 | ||||
-rw-r--r-- | TODO | 3 | ||||
-rwxr-xr-x | readable.js | 34 | ||||
-rw-r--r-- | webheader.html | 4 |
4 files changed, 25 insertions, 19 deletions
@@ -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. @@ -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 <p> 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 = "<div style=\"width: 38em; margin: auto; text-align: justify;\">" + - "<h1 style=\"text-align: center\">" + document.title + "</h1>" + + "<h1 style=\"text-align: center\">" + doc.title + "</h1>" + fresh.innerHTML + "</div>"; return 0; diff --git a/webheader.html b/webheader.html index 1c615af..b7891cc 100644 --- a/webheader.html +++ b/webheader.html @@ -1,10 +1,10 @@ <!DOCTYPE html><html><head> <style type="text/css"> -body { font-family: sans-serif; max-width: 75%; margin: auto; } +body { font-family: sans-serif; width: 75%; margin: auto; } h1 { font-size: 1.6em; text-align: center; margin-bottom: 0.2em; } h2 { font-size: 1.2em; border-bottom: thin solid black; margin-top: 0.1em; } h3 { border: thin solid black; margin: auto; background: #cd2f2f; - max-width: 15em; text-align: center; padding: 0.2em; margin-bottom: 0.3em; } + width: 15em; text-align: center; padding: 0.2em; margin-bottom: 0.3em; } h3:hover { background: #ff9657; } h3 a { color: black; text-decoration: none } h3 a:hover { text-decoration: underline } |