Aller au contenu

Utilisateur:Galdrad/monobook.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.
mw.loader.using('mediawiki.util', function () {

// install [[User:Cacycle/wikEd]] in-browser text editor
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript"></' + 'script>');
 
/*proofreadpage_default_layout='horizontal';*/

/*<pre><nowiki>*/
//Wikipedia:WikiProject User scripts | Scripts
 
function format() {
    var txt = document.editform.wpTextbox1;
    txt.value = typo(txt.value);
    txt.value = linksimplifyer(txt.value);
}
 
function typo(str){
 
    // espace
    str = str.replace(/(\n\n\n)+/g, "\n");
    str = str.replace(/- \n/g, "");
    // fix divers
    str = str.replace(/  /g, " ");
 
    // typographie
    str = str.replace(/ -/g, " —");
    str = str.replace(/- /g, "— ");
    str = str.replace(/ - /g, " — ");
    str = str.replace(/ -,/g, " —,");
    str = str.replace(/ - ,/g, " —,");
 
    str = str.replace(/( *);( *)/g, " ; ");
    str = str.replace(/( *)\!( *)/g, " ! ");
    str = str.replace(/( *):( *)/g, " : ");
    str = str.replace(/( *)\?( *)/g, " ? ");
    str = str.replace(/( *),( *)/g, ", ");
    str = str.replace(/(\[\[.*?) :/g, "$1:");
    str = str.replace(/: (.*?\]\])/g, ":$1");
 
    str = str.replace(/([^'])'([^'])/g, "$1’$2");
    str = str.replace(/’ /g, "’");
    str = str.replace(/ ’/g, "’");
    str = str.replace(/ ’ /g, "’");
    str = str.replace(/ '',/g, "'',");
    str = str.replace(/ ''\./g, "''.");    
    str = str.replace(/ \./g, "\.");
    str = str.replace(/’test’/g, "'test'");
    str = str.replace(/\[\[[Ii]mage : /g, "[[Image:");
    str = str.replace(/\[\[[Ii]mage :/g, "[[Image:");
    str = str.replace(/\[\[[Ii]mage: /g, "[[Image:"); 
 
    str = str.replace(/\.\.\./g, "…");
    str = str.replace(/\.\.\.\.+/g, "\.\.\.");
    str = str.replace(/etc\.\.+/g, "etc\.");
 
    str = str.replace(/oeu/g, "œu");
    str = str.replace(/O[Ee]/g, "Œ");
 
    str = str.replace(/"([^"].*?)"/g, "«$1»");
    str = str.replace(/( *)«( *)/g, " « ");
    str = str.replace(/\n «/g, "\n« ");
    str = str.replace(/( *)»( *)/g, " » ");
    str = str.replace(/ « text » /g, "\"text\"");
    str = str.replace(/» ,/g, "»,");
 
    str = str.replace(/(\f*)’(\f*)/g, "’");
 
    // fix catégories
    str = str.replace(/\[\[ ?[Cc]ategory/g, "[[Catégorie");
    str = str.replace(/\[\[ ?[Cc]atégorie ?: ?/g, "[[Catégorie:");
 
    // réparation liens internes
    str = str.replace(/\[\[ ?([^\]]*?) ?\]\]/g, "[[$1]]");
    str = str.replace(/\[\[([^\]]*?)( |_)#([^\]]*?)\]\]/g, "[[$1#$3]]");
 
    // syntaxe wiki
    str = str.replace(/<i>(.*?)<\/i>/gi, "''$1''");
    str = str.replace(/<b>(.*?)<\/b>/gi, "'''$1'''");
    str = str.replace(/<br\/>/gi, "<br />");
    str = str.replace(/<br>/gi, "<br />");
 
    //* puces
    str = str.replace(/^([\*#]+) /gm, "$1");
    str = str.replace(/^([\*#]+)/gm, "$1 ");
 
    //mise en page
    str = str.replace(/\n*(\{\{Titre)/g, "\n$1");
    str = str.replace(/\n*(\{\{Navigateur)/g, "\n$1");
    str = str.replace(/\[\[(.*?) —/g, "\[\[$1 -");
    str = str.replace(/\|( *)—( *)/g, "\|");
 
    return trim(str);
}
 
//simplifier certains liens : [[Dog|dog]] to [[dog]] and [[Dog|dogs]] to [[dog]]s
function linksimplifyer(str){
  var m = str.match(/\[\[([^[]*?)\|([^[]*?)\]\]/g);
  if (m)
  {
    for (var i = 0; i < m.length; i++)
    {
      var n_arr = m[i].toString().match(/\[\[([^[]*?)\|([^[]*?)\]\]/);
      var n = n_arr[0];
      var a = n_arr[1];
      var b = n_arr[2];
 
      if (b.indexOf(a) == 0 || b.indexOf(TurnFirstToLower(a)) == 0)
      {
        var k = n.replace(/\[\[([^\]\|]*?)\|(\1)([\w]*?)\]\]/i, "[[$2]]$3");
        str = str.replace(n, k);
      }
    }
  }
 
  str = str.replace(/\[\[([^\]\|]+)\|([^\]\|]+)\]\]([A-Za-z\'][A-Za-z]*)([\.\,\;\:\"\!\?\s\n])/g, "[[$1|$2$3]]$4");
 
  return str;
}
 
//trim start and end, trim spaces from the end of lines
function trim(str) {
   str = str.replace(/ $/gm, "");
   return str.replace(/^\s*|\s*$/g, "");
}
 
//turns first character to lowercase
function TurnFirstToLower(input) {
  if (input != "")
  {
    var input = trim(input);
    var temp = input.substr(0, 1);
    return temp.toLowerCase() + input.substr(1, input.length);
  }
  else
    return "";
}
 
addOnloadHook(function () {
  if(document.forms.editform) {
    mw.util.addPortletLink('p-personal', 'javascript:format()', 'typo', 'ca-format', 'Corrections de la mise en page et de la typographie', '', document.getElementById('ca-edit'));
  }
});
 
function form() {
    var txt = document.editform.wpTextbox1;
    txt.value = fr(txt.value);
    txt.value = linksimplifyer(txt.value);
}
 
function fr(str){
 
    //descartes
    str = str.replace(/lorsque/g, "lors que");
    str = str.replace(/ss/g, "ſſ");
    str = str.replace(/ê/g, "eſ");
    str = str.replace(/ et /g, " & ");
    str = str.replace(/â/g, "a");
    str = str.replace(/s([a-zé])/g, "ſ$1");
    str = str.replace(/mouvements/g, "mouvemens");
    str = str.replace(/celui/g, "celuy");
    str = str.replace(/ ſoi/g, " ſoy");
    str = str.replace(/ici/g, "icy");
    str = str.replace(/notre/g, "noſtre");
    str = str.replace(/ô/g, "oſ");
    str = str.replace(/és/g, "ez");
    str = str.replace(/lui/g, "luy");
    str = str.replace(/ſait/g, "ſçait");
    str = str.replace(/quoi/g, "quoy");
    str = str.replace(/veine/g, "vene");
    str = str.replace(/très /g, "tres-");
    str = str.replace(/ moi /g, " moy ");
    str = str.replace(/([Tt])oi /g, "$1oy ");
    str = str.replace(/toi,/g, "toy,");
    str = str.replace(/ toi\./g, " toy.");
    str = str.replace(/([a-z])ait /g, "$1oit ");
    str = str.replace(/ ai /g, " ay ");
    str = str.replace(/ ’ai /g, " ’ay ");
    str = str.replace(/ effet /g, " effect ");
 
    return trim(str);
}
 
addOnloadHook(function () {
  if(document.forms.editform) {
    mw.util.addPortletLink('p-personal', 'javascript:form()', 'fr', 'ca-form', 'Corrections de la mise en page et de la typographie', '', document.getElementById('ca-edit'));
  }
});
 
var predefinedSummaries = {
    "Liste": "",
    "Lien": "Lien(s)",
    "Index": "Index",
    "Catégorie(s)": "Ajout de catégorie(s)",
    "ProbCat" : "Correction(s) des catégories",
    "Source": "Source manquante",
    "Mise en forme": "Mise en forme",
    "Compléments": "Compléments (bibliographie, image, etc.)",
    "Typographie": "Typographie"
};
 
addOnloadHook(function () {
    var summary = document.getElementById("wpSummary");
    if (!summary) return;
 
    var dropdown = document.createElement("select");
    dropdown.style.width = "10%";
 
    for (var label in predefinedSummaries) {
        var option = document.createElement("option");
        option.setAttribute("value", predefinedSummaries[label]);
        option.appendChild(document.createTextNode(label));
        dropdown.appendChild(option);
    }
 
    dropdown.onchange = function () {
        summary.value = summary.value.replace(/(\/\*.*?\*\/\s+)?.*/,
            "$1" + dropdown.options[dropdown.selectedIndex].value);
    };
 
    summary.parentNode.insertBefore(dropdown, summary.nextSibling);
});
 
/* </nowiki></pre> */

});