Utilisateur:Ftiercel/common.js
Aller à la navigation
Aller à la recherche
Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
- Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
- Internet Explorer / Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
- Opera : appuyez sur Ctrl + F5.
if (wgAction == "edit") {
var showChangeButton = document.getElementById("wpDiff");
var formattingButton = document.createElement("input");
formattingButton.id = "wpFormat";
formattingButton.name = "wpFormat";
formattingButton.type = "button";
formattingButton.accesskey = "f";
formattingButton.value = "Mettre en forme";
formattingButton.title = "Corrige les erreurs de syntaxe [f]";
formattingButton.onclick = function(e) {
var linkWithCapitalRepl = function(matchobj) {
var group1 = matchobj.replace(/^\[\[([^\]])[^\]]*?\|[^\[]*?\]\]$/g, "$1");
var group2 = matchobj.replace(/^\[\[[^\]]([^\]]*?)\|[^\[]*?\]\]$/g, "$1");
var group3 = matchobj.replace(/^\[\[[^\]][^\]]*?\|([^\[]*?)\]\]$/g, "$1");
return '[[' + group1.toUpperCase() + group2.replace(/\_/g, ' ') + '|' + group3 + ']]';
};
var linkWithoutCapitalRepl = function(matchobj) {
var group1 = matchobj.replace(/^\[\[([^\]])[^\]]*?\|[^\[]*?\]\]$/g, "$1");
var group2 = matchobj.replace(/^\[\[[^\]]([^\]]*?)\|[^\[]*?\]\]$/g, "$1");
var group3 = matchobj.replace(/^\[\[[^\]][^\]]*?\|([^\[]*?)\]\]$/g, "$1");
return '[[' + group1.toUpperCase() + group2 + '|' + group3 + ']]';
};
var templateRepl = function(matchobj) {
var group1 = matchobj.replace(/^\{\{([a-zA-Z])[^\}\|]*?(?:\|[^\}]*)?\}\}$/g, "$1");
var group2 = matchobj.replace(/^\{\{[a-zA-Z]([^\}\|]*?)(?:\|[^\}]*)?\}\}$/g, "$1");
var group3 = matchobj.replace(/^\{\{[a-zA-Z][^\}\|]*?((?:\|[^\}]*)?)\}\}$/g, "$1");
if (group2 === '' || (group2 === 'd' && group2 === 'É')) {
return '{{' + group1.toLowerCase() + group2.replace(/\_/g, ' ') + group3 + '}}';
} else {
return '{{' + group1.toUpperCase() + group2.replace(/\_/g, ' ') + group3 + '}}';
}
};
var imageRepl = function(matchobj) {
var group1 = matchobj.replace(/^\[\[(?:[Ff]ile|[Ff]ichier|[Ii]mage)\ *\:\ *([^\]])[^\]]*?(?:\|[^\]]*)?\]\]$/g, "$1");
var group2 = matchobj.replace(/^\[\[(?:[Ff]ile|[Ff]ichier|[Ii]mage)\ *\:\ *[^\]]([^\]]*?)(?:\|[^\]]*)?\]\]$/g, "$1");
var group3 = matchobj.replace(/^\[\[(?:[Ff]ile|[Ff]ichier|[Ii]mage)\ *\:\ *[^\]][^\]]*?((?:\|[^\]]*)?)\]\]$/g, "$1");
return '[[Image:' + group1.toUpperCase() + group2.replace(/\_/g, ' ') + group3 + ']]';
};
var categoryRepl = function(matchobj) {
var group1 = matchobj.replace(/^\[\[(?:[Cc]atégorie|[Cc]ategory)\ *\:\ *([^\]])[^\]]*?(?:\|[^\]]*)?\]\]$/g, "$1");
var group2 = matchobj.replace(/^\[\[(?:[Cc]atégorie|[Cc]ategory)\ *\:\ *[^\]]([^\]]*?)(?:\|[^\]]*)?\]\]$/g, "$1");
var group3 = matchobj.replace(/^\[\[(?:[Cc]atégorie|[Cc]ategory)\ *\:\ *[^\]][^\]]*?((?:\|[^\]]*)?)\]\]$/g, "$1");
return '[[Catégorie:' + group1.toUpperCase() + group2.replace(/\_/g, ' ') + group3 + ']]';
};
var ilEstANoterQueRepl = function(matchobj) {
var group1 = matchobj.replace(/^(?:(?:Il\ est\ (?:aussi\ |également\ )?à|À)\ noter|Notons|Notez)\ (?:aussi\ |également\ )?qu(?:e\ |`|\')([0-9a-z])$/g, "$1");
return group1.toUpperCase();
};
var editTextarea = document.getElementById("wpTextbox1");
var text = editTextarea.innerHTML;
/* cela */
text = text.replace(/([^a-zA-Z0-9])([Cc])elà([\ |\.])/g, "$1$2ela$3");
/* voila */
text = text.replace(/([^a-zA-Z0-9])([Vv])oila([\ |\.,;])/g, "$1$2oilà$3");
/* Ca */
text = text.replace(/([^a-zA-Z0-9])Ca\ /g, "$1Ça ");
/* ca */
text = text.replace(/([^a-zA-Z0-9])ca\ /g, "$1ça ");
/* a */
text = text.replace(/([^a-zA-Z0-9])A\ (?!réécrire)/g, "$1À ");
/* b */
text = text.replace(/<b>([^\&]*?)\<\/b>/g, "\'\'\'$1\'\'\'");
/* i */
text = text.replace(/<i>([^\&]*?)<\/i>/g, "\'\'$1\'\'");
/* e */
text = text.replace(/<sup>e<\/sup>/g, "{{e}}");
/* cite */
text = text.replace(/\«\ *\'\'\ *(.*?)\ *\'\'\ *\»/g, "{{c|$1}}");
/* cite2 */
text = text.replace(/\'\'\ *\«\ *(.*?)\ *\»\ *\'\'/g, "{{c|$1}}");
/* cite3 */
text = text.replace(/\«\ *(.*?)\ *\»/g, "{{c|$1}}");
/* br */
text = text.replace(/<[bB][rR]\ *\/?>/g, "<br/>");
/* whiteSpace */
text = text.replace(/([a-zA-Z0-9\.\,])\ \ +([a-zA-Z0-9])/g, "$1 $2");
/* clear */
text = text.replace(/<[bB][rR]\ *(?:clear\ *\=\ *\"(?:both|all)\"|style\ *\=\ *\"clear\ *\:\ *(?:both|all)\ *\")\ *\/?>/g, "{{Clr}}");
/* strike */
text = text.replace(/<[sS][tT][rR][iI][kK][eE]\ *>([^\&]*?)<\/[sS][tT][rR][iI][kK][eE]\ *>/g, "<del>$1</del>");
/* s */
text = text.replace(/<[sS]\ *>([^\&]*?)<\/[sS]\ *>/g, "<del>$1</del>");
/* title */
text = text.replace(/(\r?\n)(\=+)\ *([^\n]*?)\ *\2\ *\1/g, "$1$2 $3 $2$1");
/* lists */
text = text.replace(/(\n)\*([a-zA-Z0-9\[])/g, "$1* $2");
/* line */
text = text.replace(/(\n)([^\*\#\r\n][^\r\n]*\.)\ *\r?\n(?=[A-Z])(?!Je\ suis\ pas\ encore\ assez)/g, "$1$2 ");
/* endOfLine */
text = text.replace(/([a-z][\.\?\!])\ *(\r?\n)/g, "$1$2");
/* url */
text = text.replace(/\[http\:\/\/desencyclopedie\.wikia\.com\/wiki\/([a-zA-Z0-9\-\_\,\;\.\!\%]+)\ +([a-zA-Z0-9\-\_\,\;\.\!\ éèçàùôêîï]+?\ *)\]/g, "[[$1|$2]]");
/* linkWithCapital */
text = text.replace(/\[\[([^\]])([^\]]*?)\|([^\[]*?)\]\]/g, linkWithCapitalRepl);
/* shortLink */
text = text.replace(/\[\[([^\]]*?)\|\1([^\[\ ]*?)\]\]/g, "[[$1]]$2");
/* linkWithoutCapital */
text = text.replace(/\[\[([^\]])([^\]]*?)\|([^\[]*?)\]\]/g, linkWithoutCapitalRepl);
/* shortLink */
text = text.replace(/\[\[([^\]]*?)\|\1([^\[\ ]*?)\]\]/g, "[[$1]]$2");
/* template */
text = text.replace(/\{\{([a-zA-Z])([^\}\|]*?)((?:\|[^\}]*)?)\}\}/g, templateRepl);
/* quote */
text = text.replace(/\{\{q\ *\|\ *([^\}\|]*?)\ *\|\ *\[\[([^\}\|\]]*?)\]\]\ *(\|\ *[^\}\|]*?)?\}\}/g, "{{q|$1|$2$3}}");
/* quote without subject */
text = text.replace(/\{\{q\|([^\}\|]*?)\|([^\}\|\]]*?)\|\ *\}\}/g, "{{q|$1|$2}}");
/* guitry */
text = text.replace(/\{\{q\ *\|\ *([^\}\|]*?)\ *\|\ *Sacha\ Guitry\ *(\|\ *[^\}\|]*?)?\}\}/g, "{{Guitry|$1$2}}");
/* image */
text = text.replace(/\[\[(?:[Ff]ile|[Ff]ichier|[Ii]mage)\ *\:\ *([^\]])([^\]]*?)((?:\|[^\]]*)?)\]\]/g, imageRepl);
/* category */
text = text.replace(/\[\[(?:[Cc]atégorie|[Cc]ategory)\ *\:\ *([^\]])([^\]]*?)((?:\|[^\]]*)?)\]\]/g, categoryRepl);
/* translation */
text = text.replace(/(?:\r?\n)?\[\[(?:nn|simple)\:[^\]]*?\]\]/g, "");
/* ilEstANoterQue */
text = text.replace(/(?:(?:Il\ est\ (?:aussi\ |également\ )?à|À)\ noter|Notons|Notez)\ (?:aussi\ |également\ )?qu(?:e\ |`|\')([0-9a-z])/g, ilEstANoterQueRepl);
editTextarea.innerHTML = text;
showChangeButton.click();
}
showChangeButton.parentNode.insertBefore(formattingButton, showChangeButton.nextSibling);
}