Utilisateur:Chphe/Verif-Copie.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./**
* Verif-Copie.js
*
* Extension de la boîte Rechercher pour lancer une recherche sur le texte sélectionné
* avec (avec g) ou sans (sans g) guillements
* avec (+t) ou sans le titre de l'article
*
* Auteurs : Chphe
* Date de dernière révision :
*/
//////////////////////ZONE PERSONNALISABLE//////////////////////
/* numéro du moteur de recherche */ var VerifCopie_numRecherche = 0; //0 pour google, 1 pour yahoo, 2 pour Live search
/////////////////FIN DE LA ZONE PERSONNALISABLE/////////////////
var VerifCopie_prefixRecherche;
function VerifCopie_texteSelec()
{
//récupération sélection
var t_selec="";
if (window.getSelection)
{
t_selec = window.getSelection().toString();
if (t_selec.length == 0 && mw.config.get('wgAction') == "edit")
{ // récupération sélection dans textarea
var txtarea = document.editform.wpTextbox1;
txtarea.focus();
var dep = txtarea.selectionStart;
var fin = txtarea.selectionEnd;
t_selec = txtarea.value.substring(dep, fin);
}
}
else if (document.getSelection)
{
t_selec = document.getSelection();
}
else if (document.selection)
{
// pour IE
t_selec = document.selection.createRange().text;
}
if (mw.config.get('wgAction') == "edit") // traitement crochets, apostrophes, guillemets
{
var reg1 = /\[\[([^\]\|]*:)? *([^\]\|:\(]*[^ \]\|:\(]) *\([^\]\|]*\| *\]\]/g;
var reg = /(\[\[([^\]\|]*\|)?)|(\]\])|(")|('''?)/g;
return t_selec.replace(reg1, "$2").replace(reg, "");
}
return t_selec;
}
function VerifCopie_lancer(avec_titre, avec_guil)
{
var texte = VerifCopie_texteSelec();
if(texte.length != 0)
{
var titre="";
if(avec_titre)
{
titre = mw.config.get('wgTitle');
var indiceP = titre.lastIndexOf(" (");
if(indiceP == -1) indiceP = titre.lastIndexOf("(");
if(indiceP != -1) titre = titre.substring(0, indiceP);
var reg=new RegExp("( )", "g");
titre = titre.replace(reg, ".")+" ";
}
if(avec_guil)
window.open(VerifCopie_prefixRecherche+titre+'%22'+texte+'%22');
else
window.open(VerifCopie_prefixRecherche+titre+texte);
}
}
function VerifCopie_ajoutOnglets()
{
if(skin == "monobook"){
var recherche = document.getElementById('p-search');
if(! recherche) return;
var div = document.createElement('div');
div.className = "pBody";
recherche.appendChild(div);
}
else if(mediaWiki.user.options.get('skin') == "vector"){
var recherche = document.getElementById('p-navigation');
if(! recherche) return;
var p_div = document.createElement('div');
p_div.className = "portal first persistent";
var p_h5 = document.createElement('h5'); // vide
p_div.appendChild(p_h5);
var div = document.createElement('div');
div.className = "body";
p_div.appendChild(div);
recherche.parentNode.insertBefore(p_div, recherche);
}
else return;
if(recherche)
{
div.innerHTML = '<table style="background:transparent"><tr><td><form name="VC_form"><select name="VC_pref" onChange="VerifCopie_prefixRecherche = document.VC_form.VC_pref.options[document.VC_form.VC_pref.selectedIndex].value;"><option value="http://www.google.fr/search?hl=fr&q=">G<option value="http://fr.search.yahoo.com/search?p=">Y<option value="http://search.live.com/results.aspx?q=">L</select></form></td><td><ul><li><a href="javascript:VerifCopie_lancer(false,false)">sans g</a> <a href="javascript:VerifCopie_lancer(true,false)">+t</a></li><li><a href="javascript:VerifCopie_lancer(false,true)">avec g</a> <a href="javascript:VerifCopie_lancer(true,true)">+t</a></li></ul></td></table>';
document.VC_form.VC_pref.selectedIndex = VerifCopie_numRecherche;
VerifCopie_prefixRecherche = document.VC_form.VC_pref.options[VerifCopie_numRecherche].value;
}
}
addOnloadHook(VerifCopie_ajoutOnglets);