summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2010-10-23 23:53:06 +0100
committerNick White <git@njw.me.uk>2010-10-23 23:53:06 +0100
commit75645602dd70f079ccf550bb5e90dffc21693429 (patch)
tree82131524085a56fc9b8ba340c98696c80e062eae
parentb5fdff68dec57116a092b08a99f1f4504da8881c (diff)
Update to run in a function, lots of doc additions
- Updated readable to run from one function, so returns work nicely now, and things are generally cleaner. - Added a readme - Added a doap rdf file - Added webpage generation to the makefile
-rw-r--r--BUGS2
-rw-r--r--INSTALL26
-rw-r--r--Makefile11
-rw-r--r--README23
-rw-r--r--TODO4
-rw-r--r--doap.ttl25
-rwxr-xr-xreadable.js110
-rw-r--r--summary.sh41
-rw-r--r--webheader.html15
9 files changed, 189 insertions, 68 deletions
diff --git a/BUGS b/BUGS
deleted file mode 100644
index 9a44697..0000000
--- a/BUGS
+++ /dev/null
@@ -1,2 +0,0 @@
-At the moment we're returning without being in a function, which is wrong. Just want to stop execution of the script...
- consider wrapping in a function, and calling that from the bookmarklet (will this work with uzbl? - maybe we can do some sort of __main__() thing?)
diff --git a/INSTALL b/INSTALL
index 46fab4e..5f649dc 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,24 +1,29 @@
+Readable is written in ECMAScript, and how to launch it varies a
+little depending on browser.
+
# Uzbl
-To use this from uzbl, add the following line to the config file (replacing
-'s' with the key to bind to):
+To use this from uzbl, add the following line to the config file
+(replacing 's' with the key to bind to):
@cbind s = script file:///path/to/readable.js
# Surf
-To use it from surf, add the following to script.js:
+To use it from surf, add the following to script.js (replacing the
+keyIdentifier if you want to bind to a key other than Ctrl-S):
(function() {
document.addEventListener('keydown', keybind, false);
- })();
+})();
- if(original === undefined) var original = false;
- function keybind(e) {
- if (!(e.keyIdentifier == "U+0053" && e.ctrlKey)) return 0; // ^s
-/* copy readable.js here, removing the line starting 'if(original' */
+function keybind(e) {
+ if (e.keyIdentifier == "U+0053" && e.ctrlKey) // ^s
+ readable();
}
+/* copy readable.js here, removing the final line 'readable()' */
+
# Other browsers; 'bookmarklet'
@@ -26,4 +31,7 @@ To use this as a 'bookmarklet', create a new bookmark with an address of:
javascript:(function(){document.body.appendChild(document.createElement('script')).src='file:///path/to/readable.js';})();
-Note that due to browsers being afraid of mixing local and remote files this may not work for http:// addresses. If this is the case, you can either run the script from a remote location (eg your webserver), or integrate it into a browser-specific extension.
+Note that due to browsers being afraid of mixing local and remote files
+this may not work for http:// addresses. If this is the case, you can
+either run the script from a remote location (eg your webserver), or
+integrate it into a browser-specific extension.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ac0a4a0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+index.html: doap.ttl README
+ @echo making webpage
+ @cat < webheader.html > $@
+ @smu < README >> $@
+ @echo '<h3><a href="latest.tar.gz">Download Readable</a><br />' >> $@
+ @echo '<a href="latest.tar.gz.sig">GPG signature</a></h3>' >> $@
+ @echo '<hr />' >> $@
+ @sh summary.sh doap.ttl | smu >> $@
+ @echo '</body></html>' >> $@
+
+.SUFFIXES: ttl html
diff --git a/README b/README
new file mode 100644
index 0000000..16c6662
--- /dev/null
+++ b/README
@@ -0,0 +1,23 @@
+Readable - Makes webpages more readable
+=======================================
+
+Readable is a simple program to remove unwanted distractions from
+webpages, in order to better enjoy reading on the web. It removes
+everything but the article from the webpage, displaying it
+simply and attractively.
+
+Running the program multiple times switches between showing the
+original page and the 'readable' version.
+
+Read the file INSTALL for information on installing it into your
+browser.
+
+This project is technically inspired by Arc90's Readability,
+but aims to be much simpler, faster, and more usable. More
+generally, it is inspired by Sean Birketts' *The Gutenberg
+Elegies* and Nicholas Carr's *The Shallows*.
+
+"The ever-present awareness of possibility to either make or
+refuse choice, was to preempt my creating any meditative space
+for myself"
+ - *Sean Birketts, The Gutenberg Elegies*
diff --git a/TODO b/TODO
index 12fd7a8..2df90e5 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,2 @@
-create makefile for script.js, and web
-create readme & ttl, to combine for web
-define width at top
+create makefile rule for packaging releases
it'd be nice to be able to run tests
diff --git a/doap.ttl b/doap.ttl
new file mode 100644
index 0000000..09c1fa8
--- /dev/null
+++ b/doap.ttl
@@ -0,0 +1,25 @@
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
+@prefix doap: <http://usefulinc.com/ns/doap#>.
+@prefix foaf: <http://xmlns.com/foaf/0.1/>.
+@prefix : <http://njw.me.uk/software/alacarte#>.
+
+:p a doap:Project;
+ doap:name "Readable";
+ doap:shortdesc "Makes webpages more readable";
+ doap:homepage <http://njw.me.uk/software/readable>;
+ doap:repository :repo;
+ doap:programming-language "ECMAScript";
+ doap:license <http://www.gnu.org/licenses/agpl.html>;
+ doap:release :v0.1;
+ doap:maintainer <http://njw.me.uk/card#i>.
+
+<http://njw.me.uk/card#i> a foaf:Person;
+ foaf:name "Nick White";
+ foaf:homepage <http://njw.me.uk>.
+
+:repo a doap:GitRepository;
+ doap:location <http://git.njw.me.uk/readable.git>.
+
+:v0.1 a doap:Version;
+ doap:revision "0.1";
+ doap:file-release <http://njw.me.uk/software/readable/readable-0.1.tar.bz2>.
diff --git a/readable.js b/readable.js
index 3d31c4f..1446240 100755
--- a/readable.js
+++ b/readable.js
@@ -5,63 +5,65 @@
*
*/
-/* NOTE: if you're using this code in another function, move this
- * line out of it, into the global scope */
if(original === undefined) var original = false;
-/* count the number of <p> tags that are direct children of parenttag */
-function count_p(parenttag)
+function readable()
{
- var n = 0;
- var c = parenttag.childNodes;
- for (var i = 0; i < c.length; i++) {
- if (c[i].tagName == "p" || c[i].tagName == "P")
- n++;
+ /* count the number of <p> tags that are direct children of parenttag */
+ function count_p(parenttag)
+ {
+ var n = 0;
+ var c = parenttag.childNodes;
+ for (var i = 0; i < c.length; i++) {
+ if (c[i].tagName == "p" || c[i].tagName == "P")
+ n++;
+ }
+ return n;
}
- return n;
-}
-
-/* if original is set, then the readable version is currently active,
- * so switch to the original html */
-if (original) {
- document.body.innerHTML = original;
- for (var i = 0; i < document.styleSheets.length; i++)
- document.styleSheets[i].disabled = false;
- original = false
- return 0;
-}
-
-original = document.body.innerHTML;
-
-var biggest_num = 0;
-var biggest_tag;
-
-/* search for tag with most direct children <p> tags */
-var t = document.getElementsByTagName("*");
-for (var i = 0; i < t.length; i++) {
- var p_num = count_p(t[i]);
- if (p_num > biggest_num) {
- biggest_num = p_num;
- biggest_tag = t[i];
+
+ /* if original is set, then the readable version is currently active,
+ * so switch to the original html */
+ if (original) {
+ document.body.innerHTML = original;
+ for (var i = 0; i < document.styleSheets.length; i++)
+ document.styleSheets[i].disabled = false;
+ original = false
+ return 0;
}
+
+ original = document.body.innerHTML;
+
+ var biggest_num = 0;
+ var biggest_tag;
+
+ /* search for tag with most direct children <p> tags */
+ var t = document.getElementsByTagName("*");
+ for (var i = 0; i < t.length; i++) {
+ var p_num = count_p(t[i]);
+ if (p_num > biggest_num) {
+ biggest_num = p_num;
+ biggest_tag = t[i];
+ }
+ }
+
+ if (biggest_num == 0) {
+ alert("Can't find any content");
+ return 1;
+ }
+
+ /* save and sanitise content of chosen tag */
+ var fresh = document.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;
+
+ document.body.innerHTML =
+ "<div style=\"width: 38em; margin: auto; text-align: justify;\">" +
+ "<h1 style=\"text-align: center\">" + document.title + "</h1>" +
+ fresh.innerHTML + "</div>";
}
-
-if (biggest_num == 0) {
- alert("Can't find any content");
- return 1;
-}
-
-/* save and sanitise content of chosen tag */
-var fresh = document.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;
-
-document.body.innerHTML =
- "<div style=\"width: 38em; margin: auto; text-align: justify;\">" +
- "<h1 style=\"text-align: center\">" + document.title + "</h1>" +
- fresh.innerHTML + "</div>";
+readable()
diff --git a/summary.sh b/summary.sh
new file mode 100644
index 0000000..453b25f
--- /dev/null
+++ b/summary.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+test $# -ne 1 && echo "usage: $0 doap" && exit 1
+
+rdf="$1"
+
+q="PREFIX doap: <http://usefulinc.com/ns/doap#>
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+SELECT ?home ?repo ?license ?maintainer ?maintainerhome ?lang
+WHERE {
+?p a doap:Project;
+ doap:homepage ?home;
+ doap:repository ?r;
+ doap:license ?license;
+ doap:programming-language ?lang;
+ doap:maintainer ?m.
+?r doap:location ?repo.
+?m foaf:name ?maintainer;
+ foaf:homepage ?maintainerhome.
+}"
+
+roqet -q -r csv -e "$q" -D /dev/stdin < $rdf | sed '/^Result/d' \
+| while read r; do
+ home=`echo $r | awk -F , '{print $2}'| sed -e 's/uri(\(.*\))/\1/'`
+ repo=`echo $r | awk -F , '{print $3}'| sed -e 's/uri(\(.*\))/\1/'`
+ licenseuri=`echo $r | awk -F , '{print $4}'| sed -e 's/uri(\(.*\))/\1/'`
+ maint=`echo $r | awk -F , '{print $5}'| sed -e 's/"\(.*\)"/\1/'`
+ mainthome=`echo $r | awk -F , '{print $6}'| sed -e 's/uri(\(.*\))/\1/'`
+ lang=`echo $r | awk -F , '{print $7}'| sed -e 's/"\(.*\)"/\1/'`
+ test "$licenseuri" = "http://www.gnu.org/licenses/gpl.html" && license="GPL"
+ test "$licenseuri" = "http://www.gnu.org/licenses/agpl.html" && license="AGPL"
+ test "$licenseuri" = "http://creativecommons.org/licenses/MIT/" && license="MIT"
+
+ cat <<- _EOF_
+- Project homepage: [$home]($home)
+- Code repository: [$repo]($repo)
+- Maintainer: [$maint]($mainthome)
+- Language: $lang
+- License: [$license]($licenseuri)
+_EOF_
+done
diff --git a/webheader.html b/webheader.html
new file mode 100644
index 0000000..1c615af
--- /dev/null
+++ b/webheader.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html><html><head>
+<style type="text/css">
+body { font-family: sans-serif; max-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; }
+h3:hover { background: #ff9657; }
+h3 a { color: black; text-decoration: none }
+h3 a:hover { text-decoration: underline }
+img { display: block; margin: auto; }
+</style>
+<link rel="alternate" type="text/turtle" title="rdf" href="doap.ttl" />
+<title>Readable - Makes webpages more readable</title>
+</head><body>