Benutzer:J*/Userscript.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) K (mal testen) |
J* (Diskussion | Beiträge) K |
||
Zeile 72: | Zeile 72: | ||
for (var abbrev in pageTable) | for (var abbrev in pageTable) | ||
{ | { | ||
− | out += abbrev + ": " + pageTable | + | out += abbrev + ": " + pageTable[abbrev]; |
} | } | ||
} | } | ||
Zeile 99: | Zeile 99: | ||
* readyHook : void function (void) which will be called at the end | * readyHook : void function (void) which will be called at the end | ||
*/ | */ | ||
− | function bl2_modifyPage( pagename, modifierHook, modifierArg, readyHook, summary ) | + | function bl2_modifyPage( pagename, modifierHook, modifierArg, readyHook, summary, readonly = false ) |
{ | { | ||
bl2_mP_struct.pagename = pagename; | bl2_mP_struct.pagename = pagename; | ||
Zeile 106: | Zeile 106: | ||
bl2_mP_struct.fn_ready = readyHook; | bl2_mP_struct.fn_ready = readyHook; | ||
bl2_mP_struct.summary = summary; | bl2_mP_struct.summary = summary; | ||
+ | bl2_mP_struct.readonly = readonly; | ||
bl2_iframeInit(); | bl2_iframeInit(); | ||
} | } | ||
− | var bl2_mP_struct = { pagename: null, fn_modifier: null, fn_ready: null, modifier_arg: null, summary: null }; | + | var bl2_mP_struct = { pagename: null, fn_modifier: null, fn_ready: null, modifier_arg: null, summary: null, readonly: null }; |
function bl2_iframeInit() | function bl2_iframeInit() | ||
Zeile 123: | Zeile 124: | ||
document.getElementById("bl2_iframe").onload = bl2_iframeComplete2; | 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 ); | 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(); | document.getElementById("bl2_iframe").contentWindow.document.getElementById("editform").submit(); | ||
} | } |
Version vom 20. September 2008, 20:10 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 += ">";
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 == "?" )
{
var out;
for (var abbrev in pageTable)
{
out += abbrev + ": " + pageTable[abbrev];
}
}
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 = 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" );
alert(data.match(reg).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 = "";
}