User:JuhkoDev/buttons.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:JuhkoDev/buttons. |
//TitleButtons adds action buttons after page title. They are used to respond to vandalism.
//<includeonly><nowiki>
addOnloadHook(j_titlebuttons);
addOnloadHook(revertlinks);
addOnloadHook(topbarlinks);
function edit_tt() {
document.getElementById("editform").wpTextbox1.innerHTML = "{{subst:Welcome}}" + " --~~"+"~~\r\n" + document.getElementById("editform").wpTextbox1.innerHTML;
document.getElementById("editform").wpSummary.value = "Added welcome-template ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function edit_test() {
document.getElementById("editform").wpTextbox1.innerHTML += "\r\n{{subst:Test}}" + " --~~"+"~~";
document.getElementById("editform").wpSummary.value = "Warning #1 ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function edit_test2() {
document.getElementById("editform").wpTextbox1.innerHTML += "\r\n{{subst:Test2}}" + " --~~"+"~~";
document.getElementById("editform").wpSummary.value = "Warning #2 ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function edit_test3() {
document.getElementById("editform").wpTextbox1.innerHTML += "\r\n{{subst:Test3}}" + " --~~"+"~~";
document.getElementById("editform").wpSummary.value = "Warning #3 ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function edit_test4() {
document.getElementById("editform").wpTextbox1.innerHTML += "\r\n{{subst:Test4}}" + " --~~"+"~~";
document.getElementById("editform").wpSummary.value = "Last warning ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function edit_uwv1() {
document.getElementById("editform").wpTextbox1.innerHTML += "\r\n{{subst:uw-vandalism1}}" + " --~~"+"~~";
document.getElementById("editform").wpSummary.value = "Uw-vandalism1 ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function edit_uwv2() {
document.getElementById("editform").wpTextbox1.innerHTML += "\r\n{{subst:uw-vandalism2}}" + " --~~"+"~~";
document.getElementById("editform").wpSummary.value = "Uw-vandalism2 ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function edit_uwv3() {
document.getElementById("editform").wpTextbox1.innerHTML += "\r\n{{subst:uw-vandalism3}}" + " --~~"+"~~";
document.getElementById("editform").wpSummary.value = "Uw-vandalism3 ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function edit_uwv4() {
document.getElementById("editform").wpTextbox1.innerHTML += "\r\n{{subst:uw-vandalism4}}" + " --~~"+"~~";
document.getElementById("editform").wpSummary.value = "Uw-vandalism4 ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function edit_uwv5() {
document.getElementById("editform").wpTextbox1.innerHTML += "\r\n{{subst:uw-vandalism5}}" + " --~~"+"~~";
document.getElementById("editform").wpSummary.value = "Uw-vandalism5 ([[User:JuhkoDev/buttons.js|TB]])";
document.getElementById("editform").submit();
}
function y1() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=y1"; }
function g6() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=g6"; }
function notab() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=notab"; }
function breaks() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=breaks"; }
function bold() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=bold"; }
function stub() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=stub&jtb_param="+escape(document.getElementById("stubInput").value); }
function tt() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=tt"; }
function test() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=test"; }
function test2() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=test2"; }
function test3() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=test3"; }
function test4() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=test4"; }
function uwv1() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=uwv1"; }
function uwv2() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=uwv2"; }
function uwv3() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=uwv3"; }
function uwv4() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=uwv4"; }
function uwv5() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=uwv5"; }
function sendmessage() { document.location.href = "http://en.wikipedia.org/w/index.php?title="+escape(wgPageName)+"&action=edit&jtb=true&jtb_action=message&jtb_param="+escape(document.getElementById("message").value); }
function j_titlebuttons() {
var jtbdiv=document.createElement("div");
document.getElementById("firstHeading").appendChild(jtbdiv);
if(wgIsArticle==true) {
//pikalisäyspainikkeet
switch(wgNamespaceNumber) {
//Artikkeli
case 0:
jtbdiv.innerHTML = "<span style='font-size:11px'>Delete:</span><input type='button' value='G1' title='G1' style='font-size:9px;cursor:pointer;' onClick='y1();'><input type='button' value='G6' title='G6' style='font-size:9px;cursor:pointer;' onClick='g6();'> <span style='font-size:11px'>General:</span><input type='button' value='Notability' title='Notability' style='font-size:9px;cursor:pointer;' onClick='notab();'><br /><span style='font-size:11px'>Stub:</span><input type='text' id='stubInput'><input type='submit' value='OK' title='Stub' onClick='stub();' style='font-size:9px;cursor:pointer;'> <span style='font-size:11px'>Quick-add:</span><input type='button' value='Automatic bolding' title='Makes article name bold' onClick='bold();' style='font-size:9px;cursor:pointer;'><input type='button' value='Breaks' title='Removes triple line breaks' onClick='breaks();' style='font-size:9px;cursor:pointer;'>";
break;
//Keskustelu käyttäjästä
case 3:
jtbdiv.innerHTML = "<input type='button' value='Welcome' title='Welcome' style='font-size:9px;cursor:pointer;' onClick='tt();'><input type='button' value='Test' style='font-size:9px;cursor:pointer;' title='Test' onClick='test();'><input type='button' value='Test2' title='Test2' style='font-size:9px;cursor:pointer;' onClick='test2();'><input type='button' value='Test3' title='Test3' style='font-size:9px;cursor:pointer;' onClick='test3();'><input type='button' value='Test4' title='Test4' style='font-size:9px;cursor:pointer;' onClick='test4();'><br /><span style='font-size:13px'>Vandalism: </span><input type='button' value='UWV-1' title='UWV-1' style='font-size:9px;cursor:pointer;' onClick='uwv1();'><input type='button' value='UWV-2' title='UWV-2' style='font-size:9px;cursor:pointer;' onClick='uwv2();'><input type='button' value='UWV-3' title='UWV-3' style='font-size:9px;cursor:pointer;' onClick='uwv3();'><input type='button' value='UWV-4' title='UWV-4' style='font-size:9px;cursor:pointer;' onClick='uwv4im();'><input type='button' value='UWV-4im' title='UWV-4im' style='font-size:9px;cursor:pointer;' onClick='uwv5();'><br /><span style='font-size:13px'>Send message: </span><input type='text' size='100' id='message'><input type='submit' value='OK' style='font-size:10px;cursor:pointer;' title='Jättää kirjoitetun viestin' onClick='sendmessage();'>";
break;
}
}
if((wgAction=="edit") || (wgAction=="submit")) {
if(!(wgPageName=="Special:MovePage")) {
if(getValue("jtb")=="true") {
if(!(wgArticleId==0)) {
try {
document.getElementById("editform").style.display="none";
getElementsByClass("mw-undo-success")[0].style.display="none";
document.getElementById("contentSub").style.display="none";
document.getElementById("wikiDiff").style.display="none";
}
catch(err) {
}
}
var sig="--~~"+""+"~~";
var param=getValue("jtb_param");
switch(getValue("jtb_action")) {
case "y1":
if(document.getElementById("wpTextbox1").innerHTML.toLowerCase().indexOf("{{db-g1") == -1) document.getElementById("wpTextbox1").innerHTML = "{{db-g1}}\n" + document.getElementById("wpTextbox1").innerHTML;
document.getElementById("wpSummary").value = "Requested speedy deletion ([[WP:CSD#G1|G1]]) ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "g6":
if(document.getElementById("wpTextbox1").innerHTML.toLowerCase().indexOf("{{db-g6") == -1) document.getElementById("wpTextbox1").innerHTML = "{{db-g6}}\n" + document.getElementById("wpTextbox1").innerHTML;
document.getElementById("wpSummary").value = "Requested speedy deletion ([[WP:CSD#G6|G6]]) ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "notab":
if(document.getElementById("wpTextbox1").innerHTML.toLowerCase().indexOf("{{notability") == -1) document.getElementById("wpTextbox1").innerHTML = "{{Notability|{{subst:DATE}}}}\n" + document.getElementById("wpTextbox1").innerHTML;
document.getElementById("wpSummary").value = "Added {{[[Template:Notability|Notability]]}} ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "breaks":
while(document.getElementById("wpTextbox1").innerHTML.indexOf("\n\n\n") > -1) {
document.getElementById("wpTextbox1").innerHTML = document.getElementById("editform").wpTextbox1.innerHTML.replace("\n\n\n","\n\n");
}
document.getElementById("wpSummary").value = "Removing triple line breaks ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "bold":
document.getElementById("editform").wpTextbox1.innerHTML = document.getElementById("editform").wpTextbox1.innerHTML.replace(getrealname(wgTitle),"'''"+getrealname(wgTitle)+"'''");
//Kaksinkertaisen lihavoinnin poisto
document.getElementById("editform").wpTextbox1.innerHTML = document.getElementById("editform").wpTextbox1.innerHTML.replace("''''''","'''");
document.getElementById("editform").wpTextbox1.innerHTML = document.getElementById("editform").wpTextbox1.innerHTML.replace("''''''","'''");
document.getElementById("editform").wpSummary.value = "Automatic bolding ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "stub":
if(document.getElementById("wpTextbox1").innerHTML.toLowerCase().indexOf("stub}}") == -1) {
if(param=="")
{ document.getElementById("wpTextbox1").innerHTML += "\n{{stub}}" }
else
{ document.getElementById("wpTextbox1").innerHTML += "\n{{"+unescape(param)+"-stub}}" }
document.getElementById("wpSummary").value = "[[WP:Stub|Stub]]";
}
break;
case "tt":
document.getElementById("wpTextbox1").innerHTML = "{{subst:Welcome}} "+sig+"\n\n" + document.getElementById("wpTextbox1").innerHTML;
document.getElementById("wpSummary").value = "Added Welcome-template ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "test":
document.getElementById("wpTextbox1").innerHTML += "\n{{subst:Test}} "+sig;
document.getElementById("wpSummary").value = "Warning #1 ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "test2":
document.getElementById("wpTextbox1").innerHTML += "\n{{subst:Test2}} "+sig;
document.getElementById("wpSummary").value = "Warning #2 ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "test3":
document.getElementById("wpTextbox1").innerHTML += "\n{{subst:Test3}} "+sig;
document.getElementById("wpSummary").value = "Warning #3 ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "test4":
document.getElementById("wpTextbox1").innerHTML += "\n{{subst:Test4}} "+sig;
document.getElementById("wpSummary").value = "Last warning ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "uwv1":
document.getElementById("wpTextbox1").innerHTML += "\n{{subst:uw-vandalism1}} "+sig;
document.getElementById("wpSummary").value = "Uw-vandalism1 ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "uwv2":
document.getElementById("wpTextbox1").innerHTML += "\n{{subst:uw-vandalism2}} "+sig;
document.getElementById("wpSummary").value = "Uw-vandalism2 ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "uwv3":
document.getElementById("wpTextbox1").innerHTML += "\n{{subst:uw-vandalism3}} "+sig;
document.getElementById("wpSummary").value = "Uw-vandalism3 ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "uwv4":
document.getElementById("wpTextbox1").innerHTML += "\n{{subst:uw-vandalism4}} "+sig;
document.getElementById("wpSummary").value = "Uw-vandalism4 ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "uwv4im":
document.getElementById("wpTextbox1").innerHTML += "\n{{subst:uw-vandalism4im}} "+sig;
document.getElementById("wpSummary").value = "Uw-vandalism4im ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "message":
document.getElementById("wpTextbox1").innerHTML += "\n"+unescape(param);
document.getElementById("wpSummary").value = "Quick-added message: "+unescape(param)+" ([[User:JuhkoDev/buttons.js|TB]])";
break;
case "revert":
document.getElementById("wpSummary").value = "Reverted to revision "+getValue("oldid")+" ([[User:JuhkoDev/buttons.js|TB]])";
break;
}
if(!(wgArticleId==0)) submitEditform();
}
else
{
jtbdiv.innerHTML = "<input type='button' value='Save' style='font-size:13px; font-weight:bold; cursor:pointer;' onClick='submitEditform();'><input type='button' value='Save as minor' style='font-size:9px; cursor:pointer;' onClick='markAsMinor();'>"+jtbdiv.innerHTML;
switch(wgNamespaceNumber) {
case 3:
jtbdiv.innerHTML += " <span style='font-size:13px'>Quick-add: </span><input type='button' value='Welcome' style='font-size:9px; cursor:pointer;' onClick='edit_tt();'><input type='button' value='Test' style='font-size:9px; cursor:pointer;' onClick='edit_test();'><input type='button' value='Test2' style='font-size:9px; cursor:pointer;' onClick='edit_test2();'><input type='button' value='Test3' style='font-size:9px; cursor:pointer;' onClick='edit_test3();'><input type='button' value='Test4' style='font-size:9px; cursor:pointer;' onClick='edit_test4();'><br><span style='font-size:13px'>Vandalism: </span><input type='button' value='UWV-1' style='font-size:9px; cursor:pointer;' onClick='edit_uwv1();'><input type='button' value='UWV-2' style='font-size:9px; cursor:pointer;' onClick='edit_uwv2();'><input type='button' value='UWV-3' style='font-size:9px; cursor:pointer;' onClick='edit_uwv3();'><input type='button' value='UWV-4' style='font-size:9px; cursor:pointer;' onClick='edit_uwv4();'><input type='button' value='UWV-4im' style='font-size:9px; cursor:pointer;' onClick='edit_uwv4im();'>";
break;
}
}
}
}
}
function submitEditform() {document.getElementById('editform').submit();}
function markAsMinor() {document.getElementById('wpMinoredit').checked=true; document.getElementById('editform').submit();}
function getValue(varname)
{
// First, we load the URL into a variable
var url = window.location.href;
if(url.indexOf("?")==-1) return "";
// Next, split the url by the ?
var qparts = url.split("?");
// Check that there is a querystring, return "" if not
if (qparts.length == 0)
{
return "";
}
// Then find the querystring, everything after the ?
var query = qparts[1];
// Split the query string into variables (separates by &s)
var vars = query.split("&");
// Initialize the value with "" as default
var value = "";
// Iterate through vars, checking each one for varname
for (i=0;i<vars.length;i++)
{
// Split the variable by =, which splits name and value
var parts = vars[i].split("=");
// Check if the correct variable
if (parts[0] == varname)
{
// Load value into variable
value = parts[1];
// End the loop
break;
}
}
// Convert escape code
value = unescape(value);
// Convert "+"s to " "s
value.replace(/\+/g," ");
// Return the value
return value;
}
//Artikkelien linkkipalkkiin lisäys
function addTab(tabtitle,tablink,tooltip,tabid) {
switch(skin) {
case "vector": var topbar=document.getElementById("p-views").getElementsByTagName("ul")[0]; break;
default: var topbar=getElementsByClass("pBody")[0].getElementsByTagName("ul")[0]; break;
}
topbar.innerHTML += '<li id="'+tabid+'"><a href="'+tablink+'" title="'+tooltip+'"><span>'+tabtitle+'</span></a></li>';
}
//Yläpalkkilinkkejä
function topbarlinks() {
//Artikkelin googletus
if(wgNamespaceNumber==0) addTab('Google','http://www.google.fi/search?q='+googlestring(wgTitle),'Google-search with article name', 'ca-google');
}
function googlestring(txt) {
var txt2=txt;
while(txt2.indexOf(' ') > -1) { txt2=txt2.replace(' ','+'); }
while(txt2.indexOf('_') > -1) { txt2=txt2.replace('_','+'); }
return txt2;
}
//Palautuslinkit
function revertlinks() {
if((!(getValue("oldid")==wgCurRevisionId)) && (!(getValue("oldid")=="")) && (getValue("diff")=="")) {
addTab('Revert','/w/index.php?title='+escape(wgPageName)+'&action=edit&oldid='+getValue("oldid")+'&jtb=true&jtb_action=revert','Revert to this revision','ca-revert');
}
else if((!(getValue("diff")=="")) && (!(getValue("oldid")=="")) && (!(getValue("diff")==""))) {
document.getElementById("mw-diff-ntitle1").innerHTML += " <strong>(<a href='"+document.getElementById("mw-diff-ntitle1").getElementsByTagName("a")[2].href+"&jtb=true' title='Quick undo (not same as rollback)'>quick-undo</a>)</strong>";
}
if(wgAction=="history") {
var litags=document.getElementById("pagehistory").getElementsByTagName("li");
var reverturl;
for(i = 0; i < litags.length; i++) {
if(!(i==0)) {
if(i==litags.length-1)
{
reverturl=litags[i].getElementsByTagName("a")[1].href+"&action=edit&jtb=true&jtb_action=revert";
}
else
{
reverturl=litags[i].getElementsByTagName("a")[2].href+"&action=edit&jtb=true&jtb_action=revert";
}
litags[i].innerHTML += ' (<a href="'+reverturl+'">restore</a>)';
}
}
undourl=getElementsByClass("mw-history-undo")[0].getElementsByTagName("a")[0].href+"&jtb=true";
litags[0].innerHTML += ' (<a href="'+undourl+'">quick-undo</a>)';
}
}
function getElementsByClass(searchClass,node,tag) {
// Function from http://www.dustindiaz.com/getelementsbyclass/
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}
function getrealname(txt) {
txt2=txt;
if(txt2.indexOf("(")==-1) return txt2;
else return txt2.substr(0,txt2.indexOf("(")-1);
}
//</nowiki></includeonly>