Utilisateur:Chphe/Verif-Copie.js

Un article de Wikipédia, l'encyclopédie libre.

Note : Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements : Mozilla / Konqueror / Firefox : Shift-Ctrl-R, Internet Explorer / Opera : Ctrl-F5, Safari : Cmd-R.

/**
 * 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 && 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 (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 = 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()
{
	var recherche = document.getElementById('p-search');
	if(recherche)
	{
		var div = document.createElement('div');
		div.className = "pBody";
		div.innerHTML = '<table><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>';
		recherche.appendChild(div);
 
		document.VC_form.VC_pref.selectedIndex = VerifCopie_numRecherche;
		VerifCopie_prefixRecherche = document.VC_form.VC_pref.options[VerifCopie_numRecherche].value;
	}
}
 
addOnloadHook(VerifCopie_ajoutOnglets);