MediaWiki:Gadget-Busca nos livros.js

Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/**
 * Buscas dentro de um livro
 * @source: [[:en:MediaWiki:Common.js/BookSearch.js]]
 * @author: [[:pl:User:Piotr]]
 * @author: [[:en:User:darklama]]
 * @author: Helder (https://github.com/he7d3r)
 */

function insereBuscaNosLivros() {
	var	Livro = mw.config.get('wgBookName').replace(/_/g, ' '),
		txt = 'Neste livro',
		chk = document.createElement('input'),
		lbl = document.createElement('label');

	chk.setAttribute('id', 'mw-neste-livro');
	chk.setAttribute('type', 'checkbox');

	lbl.htmlFor = 'mw-neste-livro';
	lbl.appendChild(document.createTextNode(txt));

	var searchForm = document.getElementById('searchform');

	searchForm.appendChild(chk);// ou searchBody?
	searchForm.appendChild(lbl);

	var botao = document.getElementById('mw-searchButton');
	var dica1 = botao.title; // botao.title = 'Procurar por páginas contendo este texto'

	var campo = document.getElementById('searchInput');
	var dica2 = 'Procurar por páginas do wikilivro "' + Livro + '" contendo este texto';

	chk.onclick = function() {
		if (chk.checked) {
			botao.setAttribute('title', dica2);
		} else {
			botao.setAttribute('title', dica1);
		}
	};
	searchForm.onsubmit = function() {
		if (chk.checked) {
			campo.value = campo.value + ' prefix:' + Livro;
		}
	};
	// return botao;
}

if ( $.inArray( mw.config.get('skin'), ['vector', 'nostalgia', 'cologneblue'] ) == -1
	&& 0 === mw.config.get('wgNamespaceNumber')
) {
	$(insereBuscaNosLivros);
}

// [[Categoria:Gadgets|Busca nos livros.js]]
// [[Categoria:Scripts do Wikilivros|Busca nos livros.js]]