Utilisateur:Jean-Frédéric/titlesearch.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) ;

Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
mw.loader.using('mediawiki.util', function () {

if(mw.config.get('wgNamespaceNumber')==0) addOnloadHook(addSearchTab);

function addSearchTab(){
mw.util.addPortletLink('p-cactions', 'javascript:switchDisplay()', 'Chercher', 'ca-customsearch', 'Recherche personnalisée');
}
var isDisplayed = false;


//Affiche ou masque la liste des liens.
function switchDisplay(){
	if(isDisplayed)
	{
		document.getElementById('SearchDiv').style.display = 'none';
		isDisplayed = false;
	}
	else
	{
		createLinks();
		isDisplayed = true;
		document.getElementById('SearchDiv').style.display = '';
	}
}


//Renvoie le vrai nom de l'article
//-Récupère le nom de l'article via MediaWiki
//-Remplace les underscores par des +
//-Se débarrasse des indications d'homonymie (ou pas)
function getArticleTrueName(){
	var name = mw.config.get('wgPageName').replace(/_/g, "+").replace(/\s\([^\)]+\)$/, "");
	return name;
}


//Créé la liste de liens
function createLinks(){
	var div = document.getElementById('bodyContent')
	
	SearchDiv = document.getElementById('SearchDiv');
 
	if(!SearchDiv)
	{
	    SearchDiv = document.createElement('div');
	    SearchDiv.id = "SearchDiv";
	    SearchDiv.align="center";
	    div.parentNode.insertBefore(SearchDiv, div);

	
	    initLinks()
		var tablinks = document.createElement("table")
		var line = tablinks.insertRow(-1)
		
	    for (var j = 0 ; j < linksArray.length ; j++ )
	    {
			var cell = line.insertCell(-1)
			var listLinks = document.createElement( "ul" );
			for (var i = 1 ; i < linksArray[j].length ; i++ )
			{
				li = document.createElement( "li" ) ;
				li.innerHTML = "<a href="+linksArray[j][i][1] + getArticleTrueName() + linksArray[j][i][2]+">"+linksArray[j][i][0]+"</a>";
				listLinks .appendChild( li );
			}
			cell.innerHTML = "<p>"+linksArray[j][0]+"</p>"
			cell.appendChild(listLinks);
	    }
	SearchDiv.appendChild(tablinks);
	}
}

//Définit la liste de liens, personnalisable

function initLinks(){
	linksArray=new Array();
    linksArray1 =new Array("Wikimedia");
	linksArray1.push(new Array("Wikipedia en", "http://en.wikipedia.org/w/index.php?title=Special:Search&search=", ""));
	linksArray1.push(new Array("Commons", "http://commons.wikimedia.org/w/index.php?title=Special:Search&search=", ""));
	linksArray1.push(new Array("Global WP", "http://vs.aka-online.de/cgi-bin/globalwpsearch.pl?search=", ""));
	linksArray.push(linksArray1);
	
	linksArray2 =new Array("BDD");
	linksArray2.push(new Array("MobyGames", "http://www.mobygames.com/search/quick?q=",""));
	linksArray2.push(new Array("GameFAQs", "http://www.gamefaqs.com/search/index.html?game=",""));
	linksArray2.push(new Array("GameSpot", "http://www.gamespot.com/pages/search/index.php?qs=", "&stype=all#game 2"));
	linksArray2.push(new Array("IGN", "http://search.ign.com/products?&objtName=Game&query=",""));
	linksArray2.push(new Array("1UP.com", "http://www.1up.com/do/search?type=GAMESKUS&term=",""));
	linksArray.push(linksArray2);
	
	linksArray3 =new Array("Critiques");
	linksArray3.push(new Array("Metacritic", "http://www.metacritic.com/search/process?sort=relevance&ty=3&ts=", ""));
	linksArray3.push(new Array("Game Rankings", "http://www.gamerankings.com/browse.html?search=", ""));
	linksArray3.push(new Array("Gamekult", "http://www.gamekult.com/tout/jeuxvideo/", "/"));
	linksArray3.push(new Array("JV.com", "http://www.jeuxvideo.com/cgi-bin/redsearch.cgi?range=0&textfield=",""));
	linksArray.push(linksArray3);
	
	linksArray4 =new Array("Lourd");
	linksArray4.push(new Array("Edge", "http://www.google.com/search?hl=fr&q=site%3Aedge-online.com+\"", "\""));
	linksArray4.push(new Array("Gamasutra", "http://www.google.com/search?hl=fr&q=site%3Agamasutra.com+\"", "\""));
	linksArray4.push(new Array("The Escapist", "http://www.google.com/search?hl=fr&q=site:escapistmagazine.com/articles/ +\"", "\""));
	linksArray4.push(new Array("Develop", "http://www.develop-online.net/search/features/", ""));

	linksArray.push(linksArray4);
	
}

});