Utilisateur:Abecido/Raccourcis.js
Note : après avoir enregistré 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 pressez Ctrl-F5 ou Ctrl-R (⌘-R sur un Mac) ;
- Google Chrome : Appuyez sur Ctrl-Maj-R (⌘-Shift-R sur un Mac) ;
- Internet Explorer : Maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ;
- Opera : Allez dans Menu → Settings (Opera → Préférences sur un Mac) et ensuite à Confidentialité & sécurité → Effacer les données d'exploration → Images et fichiers en cache.
mw.loader.using('jquery.textSelection');
function raccItal() {
var selection = $('#wpTextbox1').textSelection('getSelection');
if (!selection.collapsed) {
var str = selection.toString();
$('#wpTextbox1').textSelection('encapsulateSelection', {'pre': "''", 'peri': str, 'post': "''"});
}
}
function raccGras() {
var selection = $('#wpTextbox1').textSelection('getSelection');
if (!selection.collapsed) {
var str = selection.toString();
$('#wpTextbox1').textSelection('encapsulateSelection', {'pre': "'''", 'peri': str, 'post': "'''"});
}
}
function raccSc() {
var selection = $('#wpTextbox1').textSelection('getSelection');
if (!selection.collapsed) {
var str = selection.toString();
$('#wpTextbox1').textSelection('encapsulateSelection', {'pre': "{{sc|", 'peri': str, 'post': "}}"});
}
}
function raccModel() {
var selection = $('#wpTextbox1').textSelection('getSelection');
if (!selection.collapsed) {
var str = selection.toString();
$('#wpTextbox1').textSelection('encapsulateSelection', {'pre': "{{", 'peri': str, 'post': "}}"});
}
}
function raccCorr() {
var selection = $('#wpTextbox1').textSelection('getSelection');
var str = selection.toString();
$('#wpTextbox1').textSelection('encapsulateSelection', {'pre': "{{corr|"+str+"|", 'peri': str, 'post': "}}", 'replace':true});
if (str != '') {
var posCurseur = $('#wpTextbox1').textSelection('getCaretPosition');
$('#wpTextbox1').textSelection('setSelection', {'start':posCurseur - 2});
}
}
function raccRef() {
$('#wpTextbox1').textSelection('encapsulateSelection', {'pre': "<ref>", 'post': "</ref>"});
}
function raccInsec() {
var selection = $('#wpTextbox1').textSelection('getSelection');
if (selection != '') {
var str = selection.toString();
$('#wpTextbox1').textSelection('encapsulateSelection', {'pre': "{{lié|", 'peri': str, 'post': "}}"});
}
else {
$('#wpTextbox1').textSelection('encapsulateSelection', {'pre': "{{lié}}", 'post': ''});
}
}
function navPrec() {
{
var lienPrec = $("a[title='Page précédente']").prop('href');
window.open(lienPrec,"_self");
}
}
function navSuiv() {
{
var lienSuiv = $("a[title='Page suivante']").prop('href');
window.open(lienSuiv,"_self");
}
}
function navIndex() {
{
var lienSuiv = $("a[title='Index']").prop('href');
window.open(lienSuiv,"_self");
}
}
// Raccourcis de navigation dans l'espace Page
if (mw.config.get("wgNamespaceNumber") == 104) {
document.addEventListener("keydown",
function (event) {
if (event.key === "ArrowLeft" && event.altKey && event.shiftKey) {
event.preventDefault();
navPrec();
}
if (event.key === "ArrowRight" && event.altKey && event.shiftKey) {
event.preventDefault();
navSuiv();
}
if (event.key === "ArrowUp" && event.altKey && event.shiftKey) {
event.preventDefault();
navIndex();
}
});
}
// Raccourcis en mode édition
if (mw.config.get("wgAction") == "edit" || mw.config.get("wgAction") == "submit") {
document.addEventListener("keydown",
function (event) {
if (event.key === "i" && event.ctrlKey && !event.altKey) {
event.preventDefault();
raccItal();
}
if (event.key === "b" && event.ctrlKey && !event.altKey) {
event.preventDefault();
raccGras();
}
if (event.key === "q" && event.ctrlKey && !event.altKey) {
event.preventDefault();
raccSc();
}
if (event.key === "w" && event.altKey && event.ctrlKey) {
event.preventDefault();
raccModel();
}
if (event.key === "c" && event.altKey && event.ctrlKey) {
event.preventDefault();
raccCorr();
}
if ((event.key === "r" && event.altKey && event.ctrlKey) || (event.key === "r" && event.key === "AltGraph") ) {
event.preventDefault();
raccRef();
}
if (event.key === " " && event.ctrlKey) {
event.preventDefault();
raccInsec();
}
});
}