There's a variety of javascript bookmarklets out there in the
world that allow one to make the anchors in a document visible. I
find these very handy for making granular references into
documents that don't have purple numbers. (01)
Earlier today I stumbled onto a javascript bookmarklet called the
passivator: (02)
http://www.ftrain.com/ThePassivator.html (03)
that uses regular expressions and DOM to identify adverbs and
passive verb structures in web pages and highlights the offending
sections. (04)
I thought, "huh, I should be able to use that to put purple numbers
on pages", imagining I could create something like the purple
slurple bookmarklet but without requiring a mediating server. (05)
It turns out I couldn't do that in any functional way (because it
is the mediating server in purple slurple that makes the purple
number links persist) but I did come up with a nice javascript
hack that makes it easy to put purple numbers on any page. (06)
See (07)
http://www.burningchrome.com:8000/~cdent/ator.html (08)
to see it in action. (09)
I was surprised by how easy it was to do. Here's the code: (010)
-=-=-
var tagsRE=/\bh|p|li|dt|dd|pre\b/i;
var nid = 0;
var purpleStyle =
"font-family:sans-serif;font-weight:bold;font-size:x-small;text-decoration:none;color:#C8A8FF"
function purp(node){
if (node.hasChildNodes) {
var hi_cn;
for(hi_cn=0; hi_cn<node.childNodes.length; hi_cn++) {
purp(node.childNodes[hi_cn]);
}
}
if(node.nodeType == 1) {
if (tagsRE.test(node.nodeName)) {
var nidValue = "nid" + nid;
node.setAttribute('id', nidValue);
newNode = document.createElement('a');
newNode.setAttribute('href', "#" + nidValue);
newNode.setAttribute('style', purpleStyle);
newNode.innerHTML = " " + nid;
node.appendChild(newNode);
nid = nid + 1;
}
}
}
-=-=- (011)
Because this traverses the nodes of the document tree rather than
using regular expressions, it ought to be quite reliable and
customizable for which tags it should mark. (012)
Since the script is run onLoad, the source of the page does not
change, but the URLs of the links are still good if you come back
to the page (and the content hasn't changed). (013)
I feel like this could be handy piece in some larger tool but
it's late enough that I'm not sure how/where. I know Peter was
doing some things with javascript's dom support. (014)
Anyhow, it was fun, thought I better share. (015)
--
Chris Dent http://burningchrome.com:8000/~cdent/mt/ cdent@burningchrome.com
When you think of the long and gloomy history of man, you will find
more hideous crimes have been committed in the name of obedience than
have ever been committed in the name of rebellion. -- C. P. Snow (016)
--
This message is archived at: (017)
http://collab.blueoxen.net/forums/cgi-bin/mesg.cgi?a=tools-yak&i=Pine.OSX.4.53.0404070332560.816@nitrous.local (018)
|