summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2012-04-01 20:55:11 +0200
committerDavid A. Madore <david+git@madore.org>2012-04-01 20:55:11 +0200
commit15645cb85ce5ec986cf439c9704bae6114cc3629 (patch)
tree592756f55ac542e0819cc797b793376373693790
parent0f7d04eec05ac8c715f82666885869bd2be84e76 (diff)
downloaddamlengine-15645cb85ce5ec986cf439c9704bae6114cc3629.tar.gz
damlengine-15645cb85ce5ec986cf439c9704bae6114cc3629.tar.bz2
damlengine-15645cb85ce5ec986cf439c9704bae6114cc3629.zip
April's fool.
-rw-r--r--org/madore/damlengine/included.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/org/madore/damlengine/included.js b/org/madore/damlengine/included.js
index 7aa2a2b..9c035bd 100644
--- a/org/madore/damlengine/included.js
+++ b/org/madore/damlengine/included.js
@@ -1,4 +1,7 @@
+"use strict";
+
var textNodeType;
+
function textContent(n) {
if ( n.nodeType == textNodeType ) {
return n.data;
@@ -11,6 +14,7 @@ function textContent(n) {
return t;
}
}
+
function despam() {
// MSIE seems to barf... Deactivate for now
if ( (/MSIE *[1-6]\./).test(navigator.userAgent) )
@@ -44,6 +48,61 @@ function despam() {
}
}
}
+
+function permuteWord(s) {
+ if ( s.length <= 3 )
+ return s;
+ var tab = s.split("");
+ var n = tab.length - 1;
+ for ( var i=1 ; i<n ; i++ ) {
+ var j = i + Math.floor(Math.random()*(n-i));
+ if ( j == i )
+ continue;
+ var tmp = tab[j];
+ tab[j] = tab[i];
+ tab[i] = tmp;
+ }
+ return tab.join("");
+}
+
+function permuteString(s) {
+ return s.replace(/[A-Za-zÀ-ÿ]+/g, permuteWord);
+}
+
+function permuteDoc(doc) {
+ var body = doc.body;
+ var walker = doc.createTreeWalker(body, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, null, false);
+ var node = walker.nextNode();
+ while ( node ) {
+ if ( node.nodeType == Node.TEXT_NODE ) {
+ var thisnode = node;
+ node = walker.nextNode();
+ var str = permuteString(thisnode.nodeValue);
+ thisnode.parentNode.replaceChild(doc.createTextNode(str), thisnode);
+ } else if ( node.nodeType == Node.ELEMENT_NODE
+ && ( node.localName == "pre"
+ || node.localName == "code"
+ || node.localName == "script"
+ || node.localName == "style" ) ) {
+ do {
+ node = walker.nextSibling();
+ if ( node )
+ break;
+ node = walker.parentNode();
+ if ( ! node )
+ break;
+ } while ( true );
+ } else
+ node = walker.nextNode();
+ }
+}
+
+function aprilsFool() {
+ var today = new Date();
+ if ( today.getMonth() == 3 && today.getDate() == 1 )
+ permuteDoc(window.document);
+}
+
function onLoad() {
// Start with some bugware...
try {
@@ -53,4 +112,5 @@ function onLoad() {
}
// Now despam email adresses.
despam();
+ aprilsFool();
}