Utilisateur:Dr Brains/PaSDeluxe.js
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.if( mw.config.get('wgNamespaceNumber')%2 == 0) addOnloadHook(PaSDeluxe_AddLink);
function PaSDeluxe_AddLink(){
var Cactions = document.getElementById("p-cactions");
if(!Cactions) return;
var PaSLink = '<li><a href="javascript:PaSDeluxe();" title="Proposer la suppression de la page">PàS</a></li>';
Cactions.getElementsByTagName('ul')[0].innerHTML += PaSLink;
}
function PaSDeluxe(){
var SurEtCertain = confirm("Proposer la suppression de la page ?");
if(!SurEtCertain) return;
PaSDeluxe_AddBandeau();
}
function PaSDeluxe_AddBandeau(){
var Adresse = mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+mw.config.get('wgPageName').replace(/&/g,"%26")+"&action=edit§ion=0";
var NouvelleRequete = new XMLHttpRequest();
NouvelleRequete.open("GET", Adresse, true);
NouvelleRequete.onreadystatechange = function() {
if(NouvelleRequete.readyState != 4) return;
while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
document.body.innerHTML = NouvelleRequete.responseText;
var EditForm = document.getElementById("editform");
EditForm.style.display = "none";
var TextArea = document.getElementById("wpTextbox1");
var wpSummary = document.getElementById("wpSummary");
TextArea.value = "{{Admissibilité}}\n" + TextArea.value;
wpSummary.value = "{{Admissibilité}}";
var action = document.getElementById("editform").action;
var boundary = '--------123xyz';
var data = '';
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpTextbox1"\n\n' + TextArea.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpSection"\n\n' + document.editform.wpSection.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpSummary"\n\n' + wpSummary.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpMinoredit"\n\n' + document.editform.wpMinoredit.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpStarttime"\n\n' + document.editform.wpStarttime.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpEdittime"\n\n' + document.editform.wpEdittime.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpEditToken"\n\n' + document.editform.wpEditToken.value + '\n'
var ajaxSubmit = new XMLHttpRequest();
ajaxSubmit.open('POST', action, true);
ajaxSubmit.setRequestHeader('Content-Type', 'multipart/form-data; boundary='+boundary);
ajaxSubmit.onreadystatechange = function(){
if (ajaxSubmit.readyState != 4) return;
while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
document.body.innerHTML = ajaxSubmit.responseText;
if(!document.getElementById("editform")){
PaSDeluxe_GetURLs();
}else{
var DeuxiemeEssai = confirm('Problème !\n\nRéessayer ?');
if(DeuxiemeEssai) PaSDeluxe_AddBandeau();
}
}
ajaxSubmit.send(data + '--' + boundary);
}
NouvelleRequete.send(null);
}
var PaSDeluxe_SupprPageURL = false;
var PaSDeluxe_SupprPageDefaultText = "Veuillez remplacer ce texte par la motivation de suppression"
var PaSDeluxe_SupprPageListeURL = false;
var PaSDeluxe_SupprPageListeComm = "<!-- Ajouter les nouvelles requêtes au-dessus de cette ligne -->";
function PaSDeluxe_GetURLs(){
var AllDivs = document.getElementsByTagName("div");
var Bandeau = false;
for(var a=0;a<AllDivs.length;a++){
if(($(AllDivs[a]).hasClass("bandeau-niveau-grave"))&&(!Bandeau)){
Bandeau = AllDivs[a];
}
}
var Table = Bandeau.getElementsByTagName('table')[1];
if(!Table) return;
PaSDeluxe_SupprPageURL = Table.getElementsByTagName('a')[0].href;
PaSDeluxe_SupprPageListeURL = Table.getElementsByTagName('a')[1].href;
PaSDeluxe_CreateSupprPage();
}
function PaSDeluxe_CreateSupprPage(){
var NouvelleRequete = new XMLHttpRequest();
NouvelleRequete.open("GET", PaSDeluxe_SupprPageURL, true);
NouvelleRequete.onreadystatechange = function() {
if(NouvelleRequete.readyState != 4) return;
while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
document.body.innerHTML = NouvelleRequete.responseText;
var EditForm = document.getElementById("editform");
EditForm.style.display = "none";
var NewTextArea = document.createElement("textarea");
NewTextArea.id = "SupprReason";
NewTextArea.rows = 10;
NewTextArea.width = "100%";
NewTextArea.value = PaSDeluxe_SupprPageDefaultText;
EditForm.parentNode.insertBefore(NewTextArea, EditForm);
var NewSubmitButton = document.createElement("input");
NewSubmitButton.type = "button";
NewSubmitButton.value = "Publier";
NewSubmitButton.onclick = function(){
PaSDeluxe_SaveSupprPage();
}
NewSubmitButton.onselect = function(){
PaSDeluxe_SaveSupprPage();
}
EditForm.parentNode.insertBefore(NewSubmitButton, EditForm);
}
NouvelleRequete.send(null);
}
function PaSDeluxe_SaveSupprPage(){
var TextArea = document.getElementById("wpTextbox1");
var wpSummary = document.getElementById("wpSummary");
var NewTextArea = document.getElementById("SupprReason");
if(!NewTextArea) return;
TextArea.value = TextArea.value.split(PaSDeluxe_SupprPageDefaultText).join(NewTextArea.value);
wpSummary.value = "Proposition de suppression";
var action = document.getElementById("editform").action;
var boundary = '--------123xyz';
var data = '';
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpTextbox1"\n\n' + TextArea.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpSection"\n\n' + document.editform.wpSection.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpSummary"\n\n' + wpSummary.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpMinoredit"\n\n' + document.editform.wpMinoredit.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpStarttime"\n\n' + document.editform.wpStarttime.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpEdittime"\n\n' + document.editform.wpEdittime.value + '\n'
data += '--' + boundary + '\nContent-Disposition: form-data; name="wpEditToken"\n\n' + document.editform.wpEditToken.value + '\n'
var ajaxSubmit = new XMLHttpRequest();
ajaxSubmit.open('POST', action, true);
ajaxSubmit.setRequestHeader('Content-Type', 'multipart/form-data; boundary='+boundary);
ajaxSubmit.onreadystatechange = function(){
if (ajaxSubmit.readyState != 4) return;
while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
document.body.innerHTML = ajaxSubmit.responseText;
if(!document.getElementById("editform")){
PaSDeluxe_ListPageInPaS();
}else{
var DeuxiemeEssai = confirm('Problème !\n\nRéessayer ?');
if(DeuxiemeEssai) PaSDeluxe_CreateSupprPage();
}
}
ajaxSubmit.send(data + '--' + boundary);
}
function PaSDeluxe_ListPageInPaS(){
var NouvelleRequete = new XMLHttpRequest();
NouvelleRequete.open("GET", PaSDeluxe_SupprPageListeURL, true);
NouvelleRequete.onreadystatechange = function() {
if(NouvelleRequete.readyState != 4) return;
while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
document.body.innerHTML = NouvelleRequete.responseText;
var SpanId = PaSDeluxe_SupprPageListeURL.split('#')[1];
var mwHeadLine = document.getElementById(SpanId);
if(!mwHeadLine){ alert('Pas trouvé le span'); return; }
var Headline = mwHeadLine.parentNode;
var EditURL = false;
var Spans = Headline.getElementsByTagName('span');
for(var a=0;a<Spans.length;a++){
if($(Spans[a]).hasClass("editsection")){
EditURL = Spans[a].getElementsByTagName('a')[0].href;
}
}
if(!EditURL){ alert('Pas trouvé EditURL'); return; }
var EditRequete = new XMLHttpRequest();
EditRequete.open("GET", EditURL, true);
EditRequete.onreadystatechange = function() {
if(EditRequete.readyState != 4) return;
while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}
document.body.innerHTML = EditRequete.responseText;
var TextArea = document.getElementById("wpTextbox1");
var wpSummary = document.getElementById("wpSummary");
var Mod = "*{{L|"+mw.config.get('wgPageName').replace(/_/g, " ")+"}}."
var AncienTexte = TextArea.value;
var DebutAncientexte = AncienTexte.substring(0, AncienTexte.indexOf(PaSDeluxe_SupprPageListeComm));
var FinAncientexte = AncienTexte.split(DebutAncientexte).join("");
var Lines = DebutAncientexte.split('\n');
var Index = false;
for(var l=(Lines.length-1);l>-1;l--){
if((Lines[l].indexOf("*")!=-1)&&((Lines[(l+1)])||(Lines[(l+1)]==""))&&(!Index)) Index = (l+1);
}
if(!Index) Index = (Lines.length-1);
Lines[Index] = Mod;
DebutAncientexte = Lines.join('\n');
TextArea.value = DebutAncientexte+"\n"+FinAncientexte;
}
EditRequete.send(null);
}
NouvelleRequete.send(null);
}