Zum Inhalt springen

„Benutzer:Redlinux/monobook.js“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
Inhalt gelöscht Inhalt hinzugefügt
-
js - mal ohne import
Zeile 1: Zeile 1:
////// Fügt neben dem eigenen Benutzernamen eine Zahl mit den wartenden Neulingen ein. Gesuchte Wunschmentoren werden gesondert angezeigt.
importScript('Benutzer:Euku/Mentorenprogramm.js'); // [[Benutzer:Euku/Mentorenprogramm.js]]
// Idee: [[Benutzer:Stefan]], Ur-Skript: [[Benutzer:DerHexer]]
// kleine Erweiterung von [[Benutzer:Euku]]
//<nowiki>
addOnloadHook(function() { // put onload in wikibits.js
function newRequest() {
try {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
return new ActiveXObject("MSXML2.XMLHTTP");
}
} catch (e) {
return false;
}
}
var req;
if (req = newRequest()) {
var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Mentor gesucht";
req.open("GET", text, false);
req.send("");
var menteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
}
var req;
if (req = newRequest()) {
var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Wunschmentor gesucht";
req.open("GET", text, false);
req.send("");
var wmenteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
}
// From [[:en:Wikipedia:WikiProject_User_scripts/Scripts/Add_LI_link]]
function aswcAddlilink(tabs, url, name, id, title, key) {
var ta = new Array();
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
if(id) li.id = id;
li.appendChild(na);
//tabs.appendChild(li); // to end
ta_hi = document.getElementById('pt-userpage'); // to versions tab
if (ta_hi) tabs.insertBefore(li, ta_hi);
if (id) {
if (key && title) ta_hi[id] = [key, title];
else if (key) ta_hi[id] = [key, ''];
else if (title) ta_hi[id] = ['', title];
}
return li;
};
aswcAddlilink(document.getElementById('p-personal').getElementsByTagName('ul')[0], "http://de.wikipedia.org/wiki/Kategorie:Benutzer:Mentor_gesucht", menteecount , "ca-mentee", "Wartende Neulinge", "");
if (wmenteecount > 0)
aswcAddlilink(document.getElementById('p-personal').getElementsByTagName('ul')[0], "http://de.wikipedia.org/wiki/Kategorie:Benutzer:Wunschmentor_gesucht", "WM: " + wmenteecount, "ca-wmentee", "Wartende Neulinge mit Wunschmentor", "");
});
//</nowiki>
////// Der folge Teil fügt ein Tab zur Benutzerseite eines "wartenden Neulings" ein, mit dem man ihn sofort übernehmen kann.
////// von [[Benutzer:Ireas/mentorenscript.js]] (17:31, 30. August 2009), Autor ist [[Benutzer:Ireas]], kleine Änderung von [[Benutzer:DerHexer]]
//<nowiki>

/* Voraussetzungen */
/* isUserpage und isUserMainpage */
var isUserMainpageI = false;
if (wgCanonicalNamespace == "User")
if (wgTitle == wgTitle.split("/")[0])
isUserMainpageI = true;

/* UrlParameters, von PDD */
var UrlParameters = new Array ();
readparams();

function readparams() {
var asReadInUrlParameters;
var asReadInUrlParameter;

asReadInUrlParameters = location.search.substring(1, location.search.length).split("&");
for (i = 0; i < asReadInUrlParameters.length; i++) {
asReadInUrlParameter = asReadInUrlParameters[i].split("=");
UrlParameters[decodeURIComponent(asReadInUrlParameter[0])] = decodeURIComponent(asReadInUrlParameter[1]);
}
}
/* Ende der Voraussetzungen */

/* Optionale Variablen */
if(typeof mentorenbuttonplatz == 'undefined')
mentorenbuttonplatz = "";
if(typeof mentorenbuttontext == 'undefined')
mentorenbuttontext = "Als Mentee übernehmen";
/* Ende optionale Variablen */

/* Mentee übernehmen */
function addMentee() {
var editl = wgServer + wgScript + '?title=' +wgPageName + '&action=edit&irmentee=1';
if(wgUserName == wgTitle)
alert('Du willst Dich selbst für Dich als Mentor? Jaja... verarschen kann ich mich selbst...');
location.href = editl;
}

/* Mentor-Gesucht- o. Wunschmentor-Gesucht-Baustein ersetzen */
function replaceMenteeTemplate() {
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(/{{Mentor gesucht[^}]*}}/g, '{{Benutzer:' + wgUserName + '/Vorlage Mentor}}');
document.editform.wpSummary.value = 'Mentorenprogramm';
document.editform.wpSave.click();
return;
}

/* Button in die Buttonleiste einfügen */
function addMenteeButton() {
mentorgesucht = false;
links = document.getElementById('mw-normal-catlinks');
if(!links)
return;
links = links.getElementsByTagName('a');
if(!links)
return;
for(var i in links) {
if(!links[i].title)
continue;
var regmatch = links[i].title.match(/^Kategorie:Benutzer:(Wunschm|M)entor gesucht/);
if(regmatch) {
mentorgesucht = true;
break;
}
}
if(isUserMainpageI && mentorgesucht) {
switch(mentorenbuttonplatz) {
case "portlet":
var a = document.createElement("a");
a.textContent = mentorenbuttontext;
a.onclick = function() { addMentee(); };
a.style.cursor = "default";
var li = document.createElement("li");
li.appendChild(a);
var up = document.getElementById('pt-userpage');
if (up)
up.parentNode.insertBefore(li, up);
break;
case "none": // ausblenden
// nichts zu tun
break;
default:
var a = document.createElement("a");
a.onclick = function() { addMentee(); };
a.style.cursor = "default";
var span = document.createElement("span");
span.textContent = mentorenbuttontext;
a.appendChild(span);
var li = document.createElement("li");
li.appendChild(a);
var watch = document.getElementById('ca-watch') ||
document.getElementById('ca-unwatch');
if (watch)
watch.parentNode.insertBefore(li, watch);
break;
}
}
}

/* replaceMenteeTemplate aufrufen */
if(UrlParameters['irmentee'])
addOnloadHook(replaceMenteeTemplate);

addOnloadHook(addMenteeButton);
//</nowiki>

Version vom 13. Mai 2012, 13:31 Uhr

////// Fügt neben dem eigenen Benutzernamen eine Zahl mit den wartenden Neulingen ein. Gesuchte Wunschmentoren werden gesondert angezeigt.
// Idee: [[Benutzer:Stefan]], Ur-Skript: [[Benutzer:DerHexer]]
// kleine Erweiterung von [[Benutzer:Euku]]
//<nowiki>
 addOnloadHook(function() { // put onload in wikibits.js
 
  function newRequest() {
   try {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else {
        return new ActiveXObject("MSXML2.XMLHTTP");
      }
   } catch (e) {
      return false;
   }
  }
 
  var req;
    if (req = newRequest()) {
    var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Mentor gesucht";
    req.open("GET", text, false);
    req.send("");
    var menteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
  }
  var req;
    if (req = newRequest()) {
    var text = wgServer + wgScriptPath + "/api.php?format=xml&action=query&prop=categoryinfo&titles=Kategorie:Benutzer:Wunschmentor gesucht";
    req.open("GET", text, false);
    req.send("");
    var wmenteecount = req.responseXML.getElementsByTagName("categoryinfo")[0].getAttributeNode("pages").nodeValue;
  }
 
 // From [[:en:Wikipedia:WikiProject_User_scripts/Scripts/Add_LI_link]]
        function aswcAddlilink(tabs, url, name, id, title, key) {
         var ta = new Array();
         var na = document.createElement('a');
         na.href = url;
         na.appendChild(document.createTextNode(name));
         var li = document.createElement('li');
         if(id) li.id = id;
         li.appendChild(na);
         //tabs.appendChild(li); // to end
         ta_hi = document.getElementById('pt-userpage'); // to versions tab
         if (ta_hi) tabs.insertBefore(li, ta_hi);
         if (id) {
                 if (key && title) ta_hi[id] = [key, title];
                 else if (key) ta_hi[id] = [key, ''];
                 else if (title) ta_hi[id] = ['', title];
         }
         return li;
        };
        aswcAddlilink(document.getElementById('p-personal').getElementsByTagName('ul')[0], "http://de.wikipedia.org/wiki/Kategorie:Benutzer:Mentor_gesucht", menteecount , "ca-mentee", "Wartende Neulinge", "");
        if (wmenteecount > 0)
            aswcAddlilink(document.getElementById('p-personal').getElementsByTagName('ul')[0], "http://de.wikipedia.org/wiki/Kategorie:Benutzer:Wunschmentor_gesucht", "WM: " + wmenteecount, "ca-wmentee", "Wartende Neulinge mit Wunschmentor", "");
 });
//</nowiki>
////// Der folge Teil fügt ein Tab zur Benutzerseite eines "wartenden Neulings" ein, mit dem man ihn sofort übernehmen kann.
////// von [[Benutzer:Ireas/mentorenscript.js]] (17:31, 30. August 2009), Autor ist [[Benutzer:Ireas]], kleine Änderung von [[Benutzer:DerHexer]]
//<nowiki>

/* Voraussetzungen */
/* isUserpage und isUserMainpage */
var isUserMainpageI = false;
if (wgCanonicalNamespace == "User")
    if (wgTitle == wgTitle.split("/")[0])
        isUserMainpageI = true;

/* UrlParameters, von PDD */
var UrlParameters = new Array ();
readparams();

function readparams() {
    var asReadInUrlParameters;
    var asReadInUrlParameter;

    asReadInUrlParameters = location.search.substring(1, location.search.length).split("&");
    for (i = 0; i < asReadInUrlParameters.length; i++) {
        asReadInUrlParameter = asReadInUrlParameters[i].split("=");
        UrlParameters[decodeURIComponent(asReadInUrlParameter[0])] = decodeURIComponent(asReadInUrlParameter[1]);
    }
}
/* Ende der Voraussetzungen */

/* Optionale Variablen */
if(typeof mentorenbuttonplatz == 'undefined')
    mentorenbuttonplatz = "";
if(typeof mentorenbuttontext == 'undefined')
    mentorenbuttontext = "Als Mentee übernehmen";
/* Ende optionale Variablen */

/* Mentee übernehmen */
function addMentee() {
    var editl = wgServer + wgScript + '?title=' +wgPageName + '&action=edit&irmentee=1';
    if(wgUserName == wgTitle)
        alert('Du willst Dich selbst für Dich als Mentor? Jaja... verarschen kann ich mich selbst...');
    location.href = editl;
}

/* Mentor-Gesucht- o. Wunschmentor-Gesucht-Baustein ersetzen */
function replaceMenteeTemplate() {
    document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(/{{Mentor gesucht[^}]*}}/g, '{{Benutzer:' + wgUserName + '/Vorlage Mentor}}');
    document.editform.wpSummary.value = 'Mentorenprogramm';
    document.editform.wpSave.click();
    return;
}

/* Button in die Buttonleiste einfügen */
function addMenteeButton() {
    mentorgesucht = false;
    links = document.getElementById('mw-normal-catlinks');
    if(!links)
        return;
    links = links.getElementsByTagName('a');
    if(!links)
        return;
    for(var i in links) {
        if(!links[i].title)
            continue;
        var regmatch = links[i].title.match(/^Kategorie:Benutzer:(Wunschm|M)entor gesucht/);
        if(regmatch) {
            mentorgesucht = true;
            break;
        }
     }
    if(isUserMainpageI && mentorgesucht) {
        switch(mentorenbuttonplatz) {
            case "portlet":
                var a   = document.createElement("a");
                a.textContent   = mentorenbuttontext;
                a.onclick       = function() { addMentee(); };
                a.style.cursor  = "default";
                var li  = document.createElement("li");
                li.appendChild(a);
                var up = document.getElementById('pt-userpage');
                if (up)
                    up.parentNode.insertBefore(li, up);
            break;
            case "none": // ausblenden
                  // nichts zu tun
            break;
            default:
                var a   = document.createElement("a");
                a.onclick       = function() { addMentee(); };
                a.style.cursor  = "default";
                var span = document.createElement("span");
                span.textContent   = mentorenbuttontext;
                a.appendChild(span);
                var li  = document.createElement("li");
                li.appendChild(a);
                var watch = document.getElementById('ca-watch') ||
                            document.getElementById('ca-unwatch');
                if (watch)
                    watch.parentNode.insertBefore(li, watch);
            break;
        }
    }
}

/* replaceMenteeTemplate aufrufen */
if(UrlParameters['irmentee'])
    addOnloadHook(replaceMenteeTemplate);

addOnloadHook(addMenteeButton);
//</nowiki>