User:M-le-mot-dit/common.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
* TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
* @see https://meta.wikimedia.org/wiki/TemplateScript
* @update-token [[File:Pathoschild/templatescript.js]]
*/
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/i18n/fr.js');
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js');
/**************
Barre latérale
***************/
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
pathoschild.TemplateScript.add([
// Espaces et césures
{
name: 'Espaces',
position: 'cursor',
script: function(editor) {
editor.replace(/ +$/mg, '')
.replace(/ +<br *\/?>/g, '<br />')
.replace(/<ref> +/g, '<ref>')
.replace(/ +<\/ref>/g, '</ref>')
.replace(/[-¬] *(\n)([^ \|\n]+)[ \n]/g, '$2$1')
.replace(/\( /g, '(')
.replace(/ \)/g, ')')
.replace(/\)(\w)/g, ') $1')
.replace(/ {2,}/g, ' ');
}
},
// Caractères spéciaux
{
name: 'Char. spéciaux',
position: 'cursor',
script: function(editor) {
editor.replace(/ *-- */g, ' — ')
.replace(/ *_ */g, ' — ')
.replace(/\^\?/g, '¿')
.replace(/\^\!/g, '¡')
.replace(/\^-/g, '−')
.replace(/\^x/g, '×')
.replace(/\^\//g, '÷')
.replace(/=\//g, '≠')
.replace(/\+-/g, '±')
.replace(/\^'/g, '′')
.replace(/\^"/g, '″')
.replace(/\/\//g, '⁄')
.replace(/\^\./g, '·');
}
},
// S courts -> S longs
{
name: 'S longs',
position: 'cursor',
script: function(editor) {
editor.replace(/ss([\wœà-ÿ])/g, 'ſſ$1')
.replace(/s([ac-egi-zœà-ÿ])/g, 'ſ$1');
}
},
// Espace insécables
{
name: 'Lié',
position: 'cursor',
script: function(editor) {
editor.replaceSelection(function(selected) {
if (selected.length > 1) {
return '{{Nowrap|' + selected + '}}';
} else {
return ' ';
}
});
}
},
// Correction
{
name: 'Corr',
position: 'cursor',
script: function(editor) {
editor.replaceSelection(function(selected) {
return '{{Corr|' + selected + '|' + selected + '}}';});
}
},
// Majuscule
{
name: 'Majuscule',
position: 'cursor',
script: function(editor) {
editor.replaceSelection(function(selected) {
return selected.toUpperCase().charAt(0) + selected.toLowerCase().substring(1) ;
});
}
},
// Références dans le pied de page
{
name: 'Pied — Refs',
position: 'cursor',
script: function(editor) {
editor.forField('#wpFooterTextbox')
.prepend('{{smallrefs}}');
}
},
// Tansclusion fron French
{
name: 'Transclure',
position: 'cursor',
script: function(editor) {
editor.set("{{iwpage|fr}}");
}
},
// Join paragraph
{
name: 'Joindre',
position: 'cursor',
script: function(editor) {
editor.replaceSelection(function(selected) {
selected = selected.replace(/ *(\r\n|\n|\r)/gm, ' ');
return selected;
});
}
},
// End of page: nop, peh, upe
{
name: 'End of page',
position: 'cursor',
script: function(editor) {
editor.replace(/-[ \n]*$/, '{{peh}}')
.replace(/—[ \n]*$/, '—{{upe}}')
.replace(/\+[ \n]*$/, '{{upe}}')
.replace(/([^}])[ \n]*$/, '$1\n{{Nop}}');
}
},
// Paragraphes en une ligne
{
name: 'Parag.',
position: 'cursor',
script: function(editor) {
editor.replace(/([^>}\n]) *\n([^<{\|\n])/g, '$1 $2')
.replace(/ {2,}/g, ' ')
.replace(/[ \n]*$/, '');
}
},
]);
});
importScript('User:M-le-mot-dit/Shortcuts.js');