Benutzer:J*/Userscript.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) K (Schützte „Kamel:J*/Userscript.js“: Javascript [edit=sysop:move=sysop]) |
J* (Diskussion | Beiträge) |
||
Zeile 1: | Zeile 1: | ||
addOnloadHook( bl2_create ); | addOnloadHook( bl2_create ); | ||
+ | |||
+ | // == tables == | ||
+ | |||
+ | pageTable = | ||
+ | { | ||
+ | "L": "Leseze!chen", | ||
+ | "Z": "Lesezirkel", | ||
+ | "S": "SB", | ||
+ | "K": "Kleinkram", | ||
+ | "B": "Beobachtung", | ||
+ | "#": "ASDF" | ||
+ | }; | ||
+ | |||
+ | // == 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 | ||
{ | { | ||
− | + | actionAttr = val.substr(0,1); | |
+ | pageAttr = val.substr(1,1); | ||
+ | sectionAttr = val.substr(2); | ||
+ | } | ||
+ | catch(e) | ||
+ | {} | ||
+ | |||
+ | document.getElementById("bl2_notify").innerHTML = "»"; | ||
+ | if ( pageTable[pageAttr] != null && pageTable[pageAttr] != "" ) | ||
+ | { | ||
+ | if ( actionAttr == ">" ) //Goto | ||
+ | { | ||
+ | location.href = wgScript+'?title=Benutzer:'+wgUserName+'/'+escape(pageTable[pageAttr]); | ||
+ | return false; | ||
+ | } | ||
+ | else | ||
+ | bl2_modifyPage(escape(pageTable[pageAttr]), bl2_modifier, [actionAttr, sectionAttr], bl2_ready); | ||
+ | } | ||
+ | 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 ) | ||
+ | { | ||
+ | bl2_mP_struct.pagename = pagename; | ||
+ | bl2_mP_struct.fn_modifier = modifierHook; | ||
+ | bl2_mP_struct.modifier_arg = modifierArg; | ||
+ | bl2_mP_struct.fn_ready = readyHook; | ||
+ | bl2_iframeInit(); | ||
+ | } | ||
− | + | var bl2_mP_struct = { pagename: null, fn_modifier: null, fn_ready: null, modifier_arg: null }; | |
− | + | ||
+ | function bl2_iframeInit() | ||
+ | { | ||
+ | |||
+ | document.getElementById("bl2_iframe").src = wgScript+'?title=Benutzer:'+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 ) ); | ||
+ | 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) | ||
+ | { | ||
+ | document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpTextbox1").value = text ; | ||
+ | } | ||
+ | |||
+ | // == specific functions == | ||
+ | |||
+ | function bl2_modifier( data, arg ) | ||
+ | { | ||
+ | |||
+ | document.getElementById("bl2_notify").innerHTML += "»"; | ||
+ | |||
+ | if ( arg[0] == "+" ) | ||
+ | { | ||
+ | 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] == "-" ) | |
{ | { | ||
+ | reg = new RegExp( "[\\n]+\\* *\\[\\["+wgPageName+"(\\|.*?)?\\]\\]", "gi" ); | ||
+ | data = data.replace(reg, "" ); | ||
} | } | ||
+ | return data; | ||
} | } | ||
− | function | + | function bl2_ready() |
{ | { | ||
− | + | document.getElementById("bl2_notify").innerHTML += "OK"; | |
} | } | ||
− | function | + | function bl2_clear() |
{ | { | ||
− | + | document.getElementById("bl2_notify").innerHTML = ""; | |
− | + | document.getElementById("bl2_box").value = ""; | |
} | } |
Version vom 18. Juni 2008, 20:46 Uhr
addOnloadHook( bl2_create );
// == tables ==
pageTable =
{
"L": "Leseze!chen",
"Z": "Lesezirkel",
"S": "SB",
"K": "Kleinkram",
"B": "Beobachtung",
"#": "ASDF"
};
// == 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 += ">";
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 ( pageTable[pageAttr] != null && pageTable[pageAttr] != "" )
{
if ( actionAttr == ">" ) //Goto
{
location.href = wgScript+'?title=Benutzer:'+wgUserName+'/'+escape(pageTable[pageAttr]);
return false;
}
else
bl2_modifyPage(escape(pageTable[pageAttr]), bl2_modifier, [actionAttr, sectionAttr], bl2_ready);
}
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 )
{
bl2_mP_struct.pagename = pagename;
bl2_mP_struct.fn_modifier = modifierHook;
bl2_mP_struct.modifier_arg = modifierArg;
bl2_mP_struct.fn_ready = readyHook;
bl2_iframeInit();
}
var bl2_mP_struct = { pagename: null, fn_modifier: null, fn_ready: null, modifier_arg: null };
function bl2_iframeInit()
{
document.getElementById("bl2_iframe").src = wgScript+'?title=Benutzer:'+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 ) );
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)
{
document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpTextbox1").value = text ;
}
// == specific functions ==
function bl2_modifier( data, arg )
{
document.getElementById("bl2_notify").innerHTML += "»";
if ( arg[0] == "+" )
{
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] == "-" )
{
reg = new RegExp( "[\\n]+\\* *\\[\\["+wgPageName+"(\\|.*?)?\\]\\]", "gi" );
data = data.replace(reg, "" );
}
return data;
}
function bl2_ready()
{
document.getElementById("bl2_notify").innerHTML += "OK";
}
function bl2_clear()
{
document.getElementById("bl2_notify").innerHTML = "";
document.getElementById("bl2_box").value = "";
}