Benutzer:J*/Userscript.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
((hoffentlich) letzte Änderung)
 
(25 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
addOnloadHook( bl2_create );
 
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()
 
function bl2_create()
 
{
 
{
 
box = null;
 
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 += ">";
 +
html += "<form name='bl2_form' action='#' onsubmit='return bl2_submit(this);' style='display: inline;' >";
 +
html += "<input name='bl_box' id='bl2_box' type='text' style='background-color: #EEEEEE; border: none; width: 4em; font-size: 80%; color: #555555;' onchange='bl2_change( this );' onkeyup='bl2_change( this );' />";
 +
//html += "<input type='submit' style='display: inline' name='wpX' />";
 +
        html += "<span id='bl2_notify' name='bl_notify' onclick='bl2_clear();'></span>";
 +
html += "<iframe name='bl_iframe' id='bl2_iframe' style='position:fixed; top: 0px; left:0px; width: 200px; height: 400px; z-index: 1000; visibility: hidden;' src='' />";
 +
html += "</form>";
 +
 +
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
 
try
 
{
 
{
box = document.getElementById("ca-nstab-main").parentNode;
+
actionAttr = val.substr(0,1);
 +
pageAttr = val.substr(1,1);
 +
sectionAttr = val.substr(2);
 
}
 
}
 
catch(e)
 
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;
 +
}
  
el = document.createElement("LI");
+
function bl2_iframeSetText(text, summary)
el.innerHTML = "";
+
{
el.innerHTML += "&gt;";
+
document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpTextbox1").value = text ;
el.innerHTML += "<form style='display: inline' onload='bl2_submit(this.bl_box);'>";
+
        if ( summary != null && summary != "" )
el.innerHTML += "<input name='bl_box' id='bl2_box' type='text' style='background-color: #EEEEEE; border: none; width: 3em; font-size: 80%; color: #555555;' onchange='bl2_change(this);/>";
+
        document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpSummary").value = summary ;
el.innerHTML += "</form>";
+
}
 +
 
 +
// == specific functions ==
 +
 
 +
function bl2_modifier( data, arg )
 +
{
  
box.appendChild(el);
+
        document.getElementById("bl2_notify").innerHTML += "»";
  
//document.getElementById("bl2_box").change = bl2_change;
+
if ( arg[0] == "+" ) // add page
//document.getElementById("bl2_box").parentNode.submit = bl2_submit;
+
{
 +
reg = new RegExp( "(<!-- label( | [^>]* )"+arg[1]+" [^>]*-->)", "gi" );
 +
if ( arg[1] == null || data.search(reg) == -1 ) // specified section not found
 +
{
 +
reg2 = new RegExp( "(<!-- label( | [^>]* )\\* [^>]*-->)", "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, "<s>$1</s>" );
 +
}
 +
else if ( arg[0] == "?" ) // display label info
 +
{
 +
reg = new RegExp( "(=+[^=]+=+|(<!-- label( | [^>]* )-->))", "gi" );
 +
res = data.match(reg);
 +
if ( res )
 +
{
 +
alert(res.join("\n"));
 +
}
 +
}
 +
return data;
 
}
 
}
  
function bl2_submit ( bl_box )
+
function bl2_ready()
 
{
 
{
alert("Submit: "+bl_box.value);
+
document.getElementById("bl2_notify").innerHTML += "OK";
 
}
 
}
  
function bl2_change ( bl_box )
+
function bl2_clear()
 
{
 
{
alert("change: "+bl_box.value);
+
        document.getElementById("bl2_notify").innerHTML = "";
//box.value = bl_box.value.toUpperCase();
+
        document.getElementById("bl2_box").value = "";
 
}
 
}

Aktuelle Version vom 20. September 2008, 20:53 Uhr

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 += "<form name='bl2_form' action='#' onsubmit='return bl2_submit(this);' style='display: inline;' >";
	html += "<input name='bl_box' id='bl2_box' type='text' style='background-color: #EEEEEE; border: none; width: 4em; font-size: 80%; color: #555555;' onchange='bl2_change( this );' onkeyup='bl2_change( this );' />";
	//html += "<input type='submit' style='display: inline' name='wpX' />";
        html += "<span id='bl2_notify' name='bl_notify' onclick='bl2_clear();'></span>";
	html += "<iframe name='bl_iframe' id='bl2_iframe' style='position:fixed; top: 0px; left:0px; width: 200px; height: 400px; z-index: 1000; visibility: hidden;' src='' />";
	html += "</form>";

	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( "(<!-- label( | [^>]* )"+arg[1]+" [^>]*-->)", "gi" );
		if ( arg[1] == null || data.search(reg) == -1 ) // specified section not found
		{
			reg2 = new RegExp( "(<!-- label( | [^>]* )\\* [^>]*-->)", "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, "<s>$1</s>" );
	}
	else if ( arg[0] == "?" ) // display label info
	{
		reg = new RegExp( "(=+[^=]+=+|(<!-- label( | [^>]* )-->))", "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 = "";
}