Kamel:J*/Userscript.js

addOnloadHook( bl2_create );

// == tables and defines ==

userNs = "Kamel"

pageTable = {	"X": "Leseze!chen", "H": "Lesezirkel", "S": "SB", "K": "Kleinkramkiste", "B": "Beobachtete Seiten" };

// == constructors ==

function bl2_create {	box = null; box = document.getElementById("ca-watch"); if ( box == null ) box = document.getElementById("ca-unwatch"); if ( box == null ) return;

box = box.parentNode;

el = document.createElement("LI"); html = ""; html += "&gt;"; html += ""; html += ""; //html += ""; html += " "; html += ""; html += " ";

el.innerHTML = html;

box.appendChild(el);

}

function bl2_submit ( bl_form ) {	val = bl_form.bl_box.value; var actionAttr = null; var pageAttr = null; var sectionAttr = null;

try {		actionAttr = val.substr(0,1); pageAttr = val.substr(1,1); sectionAttr = val.substr(2); }	catch(e) {}

document.getElementById("bl2_notify").innerHTML = "»"; if ( val == "?" || ( pageTable[pageAttr] != null && pageTable[pageAttr] != "" )) {               if ( actionAttr == ">" ) //Goto {                       location.href = wgScript+'?title='+userNs+':'+wgUserName+'/'+escape(pageTable[pageAttr]); return false; }		else if ( val == "?" ) // only "?" -> pageTable info {			var out = ""; for (var abbrev in pageTable) {				out += (abbrev + ": " + pageTable[abbrev] + "\n"); }			alert(out); bl2_ready; }		else if ( actionAttr == "?" ) // "?..." -> label info {		       bl2_modifyPage(escape(pageTable[pageAttr]), bl2_modifier, [actionAttr, sectionAttr], bl2_ready, actionAttr+""+wgPageName+"", true);

}               else bl2_modifyPage(escape(pageTable[pageAttr]), bl2_modifier, [actionAttr, sectionAttr], bl2_ready, actionAttr+""+wgPageName+""); }	else document.getElementById("bl2_notify").innerHTML += "×";

return false; //do not submit }

function bl2_change ( bl_box ) {	if ( bl_box.value != bl_box.value.toUpperCase ) bl_box.value = bl_box.value.toUpperCase; }

// == page modification tools

/* * modifies a page (please call only one at a time) * pagename : pagename including namespace * modifierHook : function pointer to a function which accepts the current data and returns the modification data * modifierArg: arguments to the pointer * readyHook : void function (void) which will be called at the end */ function bl2_modifyPage( pagename, modifierHook, modifierArg, readyHook, summary, readonly ) {	if ( readonly === undefined ) readonly = false;

bl2_mP_struct.pagename = pagename; bl2_mP_struct.fn_modifier = modifierHook; bl2_mP_struct.modifier_arg = modifierArg; bl2_mP_struct.fn_ready = readyHook; bl2_mP_struct.summary = summary; bl2_mP_struct.readonly = readonly; bl2_iframeInit; }

var bl2_mP_struct = { pagename: null, fn_modifier: null, fn_ready: null, modifier_arg: null, summary: null, readonly: null };

function bl2_iframeInit {

document.getElementById("bl2_iframe").src = wgScript+'?title='+userNs+':'+wgUserName+'/'+bl2_mP_struct.pagename+'&action=edit'; document.getElementById("bl2_iframe").onload = bl2_iframeComplete; }

function bl2_iframeComplete {

document.getElementById("bl2_iframe").onload = bl2_iframeComplete2; bl2_iframeSetText( bl2_mP_struct.fn_modifier( bl2_iframeGetText, bl2_mP_struct.modifier_arg ), bl2_mP_struct.summary ); if (bl2_mP_struct.readonly == true) {		bl2_mP_struct.fn_ready; return; }	document.getElementById("bl2_iframe").contentWindow.document.getElementById("editform").submit; }

function bl2_iframeComplete2 {

bl2_mP_struct.fn_ready; }

function bl2_iframeGetText {	return document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpTextbox1").value; }

function bl2_iframeSetText(text, summary) {	document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpTextbox1").value = text ; if ( summary != null && summary != "" ) document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpSummary").value = summary ; }

// == specific functions ==

function bl2_modifier( data, arg ) {

document.getElementById("bl2_notify").innerHTML += "»";

if ( arg[0] == "+" ) // add page {		reg = new RegExp( "", "gi" ); if ( arg[1] == null || data.search(reg) == -1 ) // specified section not found {			reg2 = new RegExp( "", "gi" ); if ( data.search(reg) != -1 ) // try default (*) {				data = data.replace(reg2, "* "+wgPageName+"\n$1" ); }			else // no idea - put it at the end {				data += "\n\* "+wgPageName+""; }		}		else // booya! the specified section exists - put it there data = data.replace(reg, "* "+wgPageName+"\n$1" ); }	else if ( arg[0] == "-" ) // remove page {		reg = new RegExp( "[\\n]+\\* *\\[\\["+wgPageName+"(\\|.*?)?\\]\\]", "gi" ); data = data.replace(reg, "" ); }       else if ( arg[0] == "/" ) // cross out {		reg = new RegExp( "\\[\\["+wgPageName+"(\\|.*?)?\\]\\]", "gi" ); data = data.replace(reg, " $1 " ); }	else if ( arg[0] == "?" ) // display label info {		reg = new RegExp( "(=+[^=]+=+|)", "gi" ); res = data.match(reg); if ( res ) {			alert(res.join("\n")); }	}	return data; }

function bl2_ready {	document.getElementById("bl2_notify").innerHTML += "OK"; }

function bl2_clear {       document.getElementById("bl2_notify").innerHTML = ""; document.getElementById("bl2_box").value = ""; }