MediaWiki:Common.js/User:Bawolff/sandbox/Wiktionary query

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

$(function () {document.getElementById('wiktQ').innerHTML ='<form id="wiktQForm" method="GET" action="//en.wiktionary.org/w/api.php" ><input type="hidden" value="parse" name="action"/><input type="hidden" value="xml" name="format"><input type="hidden" name="xslt" value="MediaWiki:extractFirst.xsl"/> <input type="hidden" value="text" name="prop"/><fieldset><legend>Wiktionary Query</legend><label for="page">Word:</label> <input type="text" size="15" value="word" name="page" id="page"></input> <input type="submit" value="Find definition"/>


<label for="lang">Language code of word</label> <input type="text" size="3" name="lang" id="lang" value="en"></input> <label for="wiktLanguage">Language definition should be in: </label><select id="wiktLanguage" onchange="wiktLang();"><option value="en" selected >English</option><option value="fr">French</option></option><option value="es">Spanish</option></option><option value="ja">Japense</option></option><option value="it">Italian</option></option><option value="nl">Dutch</option><option value="pt">Portugese</option><option value="qqqOther">Other</option></select>
<label for="count">Number of definitions to return:</label> <input type="text" name="count" size="1" maxlength="3" value="1" id="count"/>
<label for="showWord">Title: </label> <select name="showWord"><option value="none" selected>None</option><option value="bold">Bolded</option><option value="linked">Linked</option></select> <label for="audio"> Pronounce word (if available. requires HTML5 browser): </label> <select name="audio"><option value="none" selected>Disabled</option><option value="true">Enabled</option><option value="autoplay">Autoplay</option></select>
<label for="redirects"> Use Mediawiki redirects </label><input type="checkbox" checked name="redirects"/> <label for="rd"> Do not use auto-case redirection</label> <input type="checkbox" name="rd" value="200"> <label for="exit">Hide link</label> <input type="checkbox" name="exit" id="exit" value="true"/>
<input type="submit" value="Find definition"/></fieldset></form>';});


function wiktLang () {

var sel = document.getElementById('wiktLanguage');

var val = sel[sel.selectedIndex].value; if (val === 'qqqOther') {

var lang = prompt("Enter language code of definition result. (Warning not all languages are supported)", "en");
if (!lang) return;
var opt = document.createElement("option");
opt.value = lang;
opt.appendChild(document.createTextNode(lang));
sel.appendChild(opt);
sel.selectedIndex = opt.index;

}

var form=document.getElementById('wiktQForm');

form.setAttribute('action', form.getAttribute('action').replace(/^http\:\/\/[^\.]*/, "http://" + encodeURIComponent(sel[sel.selectedIndex].value))); }