Benutzer:J*/Userscript.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) |
J* (Diskussion | Beiträge) ((hoffentlich) letzte Änderung) |
||
(13 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 60: | Zeile 60: | ||
document.getElementById("bl2_notify").innerHTML = "»"; | document.getElementById("bl2_notify").innerHTML = "»"; | ||
− | if ( pageTable[pageAttr] != null && pageTable[pageAttr] != "" ) | + | if ( val == "?" || ( pageTable[pageAttr] != null && pageTable[pageAttr] != "" )) |
{ | { | ||
if ( actionAttr == ">" ) //Goto | if ( actionAttr == ">" ) //Goto | ||
Zeile 67: | Zeile 67: | ||
return false; | 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 | else | ||
− | bl2_modifyPage(escape(pageTable[pageAttr]), bl2_modifier, [actionAttr, sectionAttr], bl2_ready); | + | bl2_modifyPage(escape(pageTable[pageAttr]), bl2_modifier, [actionAttr, sectionAttr], bl2_ready, actionAttr+"[["+wgPageName+"]]"); |
} | } | ||
else | else | ||
Zeile 91: | Zeile 106: | ||
* 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 ) | + | function bl2_modifyPage( pagename, modifierHook, modifierArg, readyHook, summary, readonly ) |
{ | { | ||
+ | if ( readonly === undefined ) | ||
+ | readonly = false; | ||
+ | |||
bl2_mP_struct.pagename = pagename; | bl2_mP_struct.pagename = pagename; | ||
bl2_mP_struct.fn_modifier = modifierHook; | bl2_mP_struct.fn_modifier = modifierHook; | ||
bl2_mP_struct.modifier_arg = modifierArg; | bl2_mP_struct.modifier_arg = modifierArg; | ||
bl2_mP_struct.fn_ready = readyHook; | bl2_mP_struct.fn_ready = readyHook; | ||
+ | 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 }; | + | 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 113: | Zeile 133: | ||
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_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(); | ||
} | } | ||
Zeile 128: | Zeile 153: | ||
} | } | ||
− | function bl2_iframeSetText(text) | + | function bl2_iframeSetText(text, summary) |
{ | { | ||
document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpTextbox1").value = text ; | document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpTextbox1").value = text ; | ||
+ | if ( summary != null && summary != "" ) | ||
+ | document.getElementById("bl2_iframe").contentWindow.document.getElementById("wpSummary").value = summary ; | ||
} | } | ||
Zeile 140: | Zeile 167: | ||
document.getElementById("bl2_notify").innerHTML += "»"; | document.getElementById("bl2_notify").innerHTML += "»"; | ||
− | if ( arg[0] == "+" ) | + | if ( arg[0] == "+" ) // add page |
{ | { | ||
reg = new RegExp( "(<!-- label( | [^>]* )"+arg[1]+" [^>]*-->)", "gi" ); | reg = new RegExp( "(<!-- label( | [^>]* )"+arg[1]+" [^>]*-->)", "gi" ); | ||
− | if ( arg[1] | + | if ( arg[1] == null || data.search(reg) == -1 ) // specified section not found |
{ | { | ||
reg2 = new RegExp( "(<!-- label( | [^>]* )\\* [^>]*-->)", "gi" ); | reg2 = new RegExp( "(<!-- label( | [^>]* )\\* [^>]*-->)", "gi" ); | ||
− | if ( data.search(reg) | + | if ( data.search(reg) != -1 ) // try default (*) |
{ | { | ||
data = data.replace(reg2, "* [["+wgPageName+"]]\n$1" ); | data = data.replace(reg2, "* [["+wgPageName+"]]\n$1" ); | ||
Zeile 158: | Zeile 185: | ||
data = data.replace(reg, "* [["+wgPageName+"]]\n$1" ); | data = data.replace(reg, "* [["+wgPageName+"]]\n$1" ); | ||
} | } | ||
− | else if ( arg[0] == "-" ) | + | else if ( arg[0] == "-" ) // remove page |
{ | { | ||
reg = new RegExp( "[\\n]+\\* *\\[\\["+wgPageName+"(\\|.*?)?\\]\\]", "gi" ); | reg = new RegExp( "[\\n]+\\* *\\[\\["+wgPageName+"(\\|.*?)?\\]\\]", "gi" ); | ||
data = data.replace(reg, "" ); | 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; | return data; |
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 += ">";
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 = "";
}