Utilisateur:Stef48/reGuilde.js

Une page de Wikipédia, l'encyclopédie libre.
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
/**
 * Présentation : [[Discussion Projet:JavaScript/2008-2009#Guilde]]
 * {{Catégorisation JS|ReGuilde}}
 */
 
// <source lang=javascript><pre><nowiki> nowiki pour empêcher MediaWiki d'interpréter les caractères spéciaux

function YGAR_youGotAReply(){
    var Content = document.getElementById('bodyContent'); // monobook, chick, myskin, simple, vector
    if(!Content) Content = document.getElementById('mw_contentholder'); //modern
    if(!Content) Content = document.getElementById('article'); // cologneblue, nostalgia, standard

    var AllH2 = Content.getElementsByTagName('h2');
    for(var h=0; h<AllH2.length; h++){
        var SectionTitle = AllH2[h];
        var SectionLink = "";
        var SectionLinkTarget = "";
        var ThisEditSection = false;
        var EditSections = SectionTitle.getElementsByTagName('span');
	for(var i=0; i<EditSections.length; i++){
            if($(EditSections[i]).hasClass('editsection')){
                ThisEditSection = EditSections[i];
                SectionLink = ThisEditSection.getElementsByTagName('a')[0].href;
                SectionLink = SectionLink.split('&action=')[0];
            }
            if($(EditSections[i]).hasClass('mw-headline')){
                SectionLinkTarget = EditSections[i].id;
            }
        }
        if(!ThisEditSection) continue;
        SectionLink = SectionLink + '#' + SectionLinkTarget + ' ' + SectionLinkTarget;
        var UserName = false;
        var Element=SectionTitle;
        while(Element){
            Element=Element.nextSibling;
            if(!Element) break;
            if(Element.tagName){
                if(Element.tagName.toLowerCase().indexOf("h")!=-1) break;
                if((Element.tagName.toLowerCase()=="p")&&(Element.innerHTML.indexOf("Demandeur")!=-1)){
                    var Links = Element.getElementsByTagName('a');
                    for(var a=0;a<Links.length;a++){
                        if(!UserName){
                            var URL = Links[a].href;
                            URL = decodeURIComponent(URL);
                            URL = URL.replace(/.*\/wiki\//, "");
                            URL = URL.replace(/.*?title=/, "");
                            URL = URL.replace(/.*:/, "");
                            URL = URL.replace(/Contributions\//, "");
                            URL = URL.replace(/&action.*/, "");
                            if(URL.indexOf("/")==-1){
                                UserName = encodeURIComponent(URL);  
                            } 
                        }                     
                    }
                }
            }
        }
        if(!UserName) continue;
        var NewLink = document.createElement('a');
        NewLink.innerHTML = "(Prévenir d'une réponse)";
        NewLink.href =  mw.config.get('wgServer')+mw.config.get('wgScript')+'?title=User talk:'+encodeURIComponent(UserName)+'&action=edit&section=new&sectionGdG='+SectionLink;
        ThisEditSection.appendChild(document.createTextNode(" - "));
        ThisEditSection.appendChild(NewLink);

    }	    
}
 
function YGAR_message(sectionGdG){
	document.getElementById('wpSummary').value = 'Demande d’aide quant aux [[Wikipédia:Questions techniques|Questions techniques]]';
	document.getElementById('wpTextbox1').value = "Bonjour,<br/>\nUn utilisateur a répondu à votre question : ["+sectionGdG+"].<br/>\nCordialement, ~~~~";
}
 
if(mw.config.get('wgPageName').match("Wikipédia:Questions_techniques") && (mw.config.get('wgAction')=="view" || mw.config.get('wgAction')=="purge")) addOnloadHook(YGAR_youGotAReply);
else if(mw.config.get('wgNamespaceNumber')==3 && mw.config.get('wgAction')=="edit")
{
   var tab = /sectionGdG=(.+)$/.exec(location.href);
   if(tab && tab.length == 2) addOnloadHook(function() { YGAR_message(decodeURIComponent(tab[1])); } )
}
// </nowiki></pre></source>