WoWEurope - Fix PRE code (EU and US forums)

By Zuo Last update Sep 16, 2008 — Installed 77 times. Daily Installs: 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

There are 3 previous versions of this script.

// ==UserScript==
// @name           WoWEurope - Fix PRE code (+US)
// @namespace      WoWEurope - Fix PRE code (+US)
// @description    Fix on the <PRE> tags, makes them more pleasant to look at! <3
// @include        http://forums.wow-europe.com/*
// @include        http://forums.worldofwarcraft.com/*
// ==/UserScript==

// Enable mouseover selecting or not? If not, you need to click the frame to select the text. I like to keep it turned off myself. ;) (1 = ON && 0 = OFF)
var mo_on = 0;

// Hook method:
//  0 = remove <br> when using Firefox to avoid too much space
//  1 = only change the style of the frame and nothing more!
var hook_method = 0;

// Format the PRE tags
var dtag = document.getElementsByTagName('pre');
for (i=0; i<dtag.length; i++) {
	dtag[i].setAttribute("id","pre_" + i);
	dtag[i].setAttribute("style","width:800px;overflow:scroll;border:1px solid #3D3D3D;margin:10px;background-color:#4A4A4A;");
	//dtag[i].setAttribute("onclick","prompt(\"Copy and paste the code in Notepad or your favorite text editor:\", this.innerHTML.replace(/(<([^>]+)>)/ig,'').replace(/&lt;/,'<').replace(/&gt;/,'>') )");
	if(mo_on==1) {
		dtag[i].setAttribute("onmouseover","setTimeout(\"getSelection().selectAllChildren(document.getElementsByTagName('pre')["+i+"])\",1)");
		dtag[i].setAttribute("onmouseout","setTimeout(\"getSelection().selectAllChildren(document.getElementsByTagName('div')[0])\",1)");
	} else {
		dtag[i].setAttribute("onclick","setTimeout(\"getSelection().selectAllChildren(document.getElementsByTagName('pre')["+i+"])\",1)");
	}
	if(hook_method==1) {
		//dtag[i].innerHTML = '<textarea id="pre_'+i+'" style="width:800px;height:50px;overflow:scroll;border:1px solid #3D3D3D;margin:10px;background-color:#4A4A4A;">'+code+'</textarea>';
		dtag[i].innerHTML = dtag[i].innerHTML + "<br><br>";
	} else {
		dtag[i].setAttribute("style",dtag[i].getAttribute("style") + ";padding:10px");
		var code = dtag[i].innerHTML;
		if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
			code = code.replace(/\<br\>/g,"");
		}
		dtag[i].innerHTML = code;
	}
}