MediaWiki:Gadget-Busca aprimorada.js
Origem: Wikilivros, livros abertos por um mundo aberto.
Nota: Após gravar, terá de limpar a cache do seu navegador para ver as alterações. Mozilla / Firefox / Safari: pressione Shift enquanto clica em Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (Command-R num Macintosh); Konqueror:: clique no botão Recarregar ou pressione F5; Opera: limpe a cache em Ferramentas → Preferências (Tools → Preferences); Internet Explorer: pressione Ctrl enquanto clica em Recarregar ou pressione Ctrl-F5.
//<source lang="JavaScript"> /** Busca Aprimorada ** * Baseado em: [[:w:en:MediaWiki:Gadget-externalsearch.js]] (versão acessada em 26/02/2008) * Autor: [[:b:pt:User:Heldergeovane]] * Descrição: Acrescenta 3 menus drop-down na página [[Especial:Search]], permitindo escolher * o wikiprojeto, o idioma e o mecanismo de busca utilizado na pesquisa. */ if ('Search' == wgCanonicalSpecialPageName) addOnloadHook(BuscaAprimorada) var caixa = [ { 'nome' : 'Idioma', 'item' : ['pt', 'en', 'es', 'fi', 'fr', 'it', 'la', 'ja', 'pl', 'nl', 'no', 'sv', 'ru', 'zh', 'meta', 'commons', 'species', 'www']}, { 'nome' : 'Projeto', 'item' : ['wikibooks', 'mediawiki', 'wikimedia', 'wikinews', 'wikipedia', 'wikiquote', 'wikisource', 'wikiversity', 'wiktionary'], 'Wikiwix' : ['book', 'mediawiki', 'commons', 'news', '', 'quote', 'source', 'versity', 'dict']}, { 'nome' : 'Buscador', 'item' : ['Padrão', 'Google', 'Yahoo', 'Bing', 'Wikiwix', 'Exalead']}, { 'nome' : 'Param', 'item' : [ [wgServer + wgScript, 'search', 'title', 'Special:Search'], ['http://www.google.com/search', 'q', 'sitesearch', wgServer], ['http://search.yahoo.com/search', 'p', 'vs', wgServer], ['http://www.bing.com/search', 'q', 'q1', 'site:' + wgServer], ['http://www.wikiwix.com/index.php', 'action', 'lang', 'pt'], ['http://www.exalead.com/search/results', 'q', 'language', 'site:' + wgServer]]}] var CaixaUrl = [] function BuscaAprimorada() { var FormBusca = document.forms['search'] || document.forms['powersearch'] if (!FormBusca) return false var searchBox = FormBusca.lsearchbox || FormBusca.search if (!searchBox) return false var CriaCaixa = function(nome, itens) { NovaCaixa = document.createElement('select') NovaCaixa.id = 'cx' + nome for (var i = 0; i < itens.length; i++){ var op = document.createElement('option') op.appendChild(document.createTextNode(itens[i])) NovaCaixa.appendChild(op) } return NovaCaixa } searchBox.style.marginLeft = '0px'; //* Originalmente o valor é '25%' var BtnPesquisa = document.getElementById('loadStatus') || FormBusca.title var N = BtnPesquisa.parentNode for (var i = 0; i < 3; i++){//Cria e posiciona cada caixa de seleção imediatamente antes do botão de pesquisa CaixaUrl[i] = CriaCaixa(caixa[i].nome, caixa[i].item) N.insertBefore(CaixaUrl[i], BtnPesquisa) } FormBusca.onsubmit = function() { var idxIdSel = document.getElementById('cxIdioma').selectedIndex var idxProjSel = document.getElementById('cxProjeto').selectedIndex var idxBuscSel = document.getElementById('cxBuscador').selectedIndex var IdSel = caixa[0].item[idxIdSel] var ProjSel = caixa[1].item[idxProjSel] var BuscSel = caixa[2].item[idxBuscSel] var ParamSel = caixa[3].item[idxBuscSel] var u = 'http://' + IdSel + '.' + ProjSel + '.org' switch (BuscSel){ case 'Padrão': ParamSel[0] = u + wgScript; break case 'Bing': u = 'site:' + u; break case 'Wikiwix': u=IdSel; FormBusca.ns0.value = caixa[1].Wikiwix[idxProjSel]; FormBusca.ns0.name = 'disp'; if( 'wikimedia' == ProjSel && 'commons' == IdSel ) { FormBusca.ns1.value = 'true'; FormBusca.ns1.name = 'img'} break case 'Exalead': u = 'site:' + u; searchBox.value += ' ' + u; break } if ('Padrão' != BuscSel) ParamSel[3] = u FormBusca.action = ParamSel[0] searchBox.name = ParamSel[1] FormBusca.title.value = ParamSel[3] FormBusca.title.name = ParamSel[2] } CaixaUrl[0].onchange = function() { var IdSel = caixa[0].item[document.getElementById('cxIdioma').selectedIndex] var ProjSel = caixa[1].item[document.getElementById('cxProjeto').selectedIndex] switch (IdSel){ case 'meta': case 'commons': case 'species': document.getElementById('cxProjeto').selectedIndex = 2; break //wikimedia case 'www': document.getElementById('cxProjeto').selectedIndex = 1; break //mediawiki default: switch (IdSel){ case 'wikimedia': case 'mediawiki': document.getElementById('cxProjeto').selectedIndex = 0; break //wikibooks } } } CaixaUrl[1].onchange = function() { var IdSel = caixa[0].item[document.getElementById('cxIdioma').selectedIndex] var ProjSel = caixa[1].item[document.getElementById('cxProjeto').selectedIndex] switch (ProjSel){ case 'wikimedia': document.getElementById('cxIdioma').selectedIndex = caixa[0].item.length - 3; break //commons case 'mediawiki': document.getElementById('cxIdioma').selectedIndex = caixa[0].item.length-1; break //www default: switch (IdSel){ case 'meta': case 'commons': case 'species': case 'www': document.getElementById('cxIdioma').selectedIndex = 0; break //pt } } } } //</source> // [[Categoria:Gadgets|Busca aprimorada.js]]