Posted on Feb 17, 2006


some bug report pages that I visit while on work nag me to madness with their inclusion of non-word-wrapped text within ‘pre’ tag.

Here is an example:

`Mine is a long and a sad tale!' said the Mouse, turning to Alice, and sighing. `It is a long tail, certainly,' said Alice, looking down with wonder at the Mouse's tail' `but why do you call it sad? And she kept on puzzling about it while the Mouse was speaking, so that her idea of the tale was something like this:

greasemonkey is perfect to take care of such irritating behavior. Armed with a decent javascript reference, an excellent greasemonkey tutorial, and plagiarized code from, I wrote my first piece of javascript code – which is also my first greasemonkey script.

Here it is:

// ==UserScript==
// @name Pre Remove
// @description Remove all Pre tags
// ==/UserScript==

//copied from
//m is the line number to wrap at, b is the line wrap char
//to insert, I don't know what c is.
String.prototype.wordWrap = function(m, b, c){
var i, j, s, r = this.split("\n");
if(m > 0) for(i in r){
for(s = r[i], r[i] = ""; s.length > m;
j = c ? m : (j = s.substr(0, m).match(/\S*$/)).input.length - j[0].length
|| j.input.length + (j = s.substr(m).match(/^\S*/)).input.length + j[0].length,
r[i] += s.substr(0, j) + ((s = s.substr(j)).length ? b : "")
r[i] += s;
return r.join("\n");

var allPre, thisPre;
allPre = document.getElementsByTagName('pre');
for (var i = 0; i < allPre.length; i++) {
thisPre = allPre[i];
preChildren = thisPre.childNodes;
for (var j = 0; j < preChildren.length; j++) {
preChildren[i].nodeValue = preChildren[i].nodeValue.wordWrap(72, "\n", false);

1 Comment

  • Dameocrat says:

    do an apt-get and install the xubuntu-desktop, or ubuntulite. It will run much better on that old computer. If you want to use firefox you would be better off with puppy, feather or Damn Small Linux. I personally like feather. It automatically detects lans, though maybe not wireless.