Utilisateur:Phe/Interwiki.js
Note : après avoir enregistré vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : Maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ou Ctrl-R (⌘-R sur un Mac) ;
- Google Chrome : Appuyez sur Ctrl-Maj-R (⌘-Shift-R sur un Mac) ;
- Internet Explorer : Maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ;
- Opera : Allez dans Menu → Settings (Opera → Préférences sur un Mac) et ensuite à Confidentialité & sécurité → Effacer les données d'exploration → Images et fichiers en cache.
// add_interwiki() perform one request per entry in this array (-1 if the native
// wiki has its own entry here). So don't add too much entry, pywikipedia interwiki
// bots can handle the missing interwikis. No entry has been added for any wiki
// w/o an Author: dedicated namespace, biggest missing are de: and es:.
var author_ns_prefix = {
'en' : 'Author',
'fr' : 'Auteur',
'it' : 'Autore',
'pt' : 'Autor',
}
function get_interwiki(data)
{
var wpTextbox1 = document.getElementById("wpTextbox1");
if (wpTextbox1 && !data.query.pages["-1"]) {
for (var ids in data.query.pages) {
wpTextbox1.value += '[[' + data.query.general.lang + ':' + data.query.pages[ids].title + ']]\n'
break;
}
}
}
function create_script_obj(url)
{
var scriptObj = document.createElement("script");
scriptObj.setAttribute("type", "text/javascript");
scriptObj.setAttribute("src", url);
document.body.appendChild(scriptObj);
}
function add_interwiki()
{
for (var lang in author_ns_prefix) {
if (lang == wgContentLanguage)
continue;
// well, hard coded... domain name would be extracted from wgServer...
var base_url = "http://" + lang + ".wikisource.org"
+ wgScriptPath
+ "/api.php?format=json&redirects";
var url = base_url
//+ '&callback=get_interwiki&action=query&prop=langlinks&lllimit=32&titles='
+ '&callback=get_interwiki&action=query&meta=siteinfo&titles='
+ encodeURIComponent(author_ns_prefix[lang] + ':' + wgTitle);
create_script_obj(url);
}
}
function addButton2(id,alt,comment,source,onclick){
var tb = document.getElementById("toolbar");
if(tb){
var image = document.createElement("img");
image.width = 46;
image.height = 22;
image.border = 0;
image.className = "mw-toolbar-editbutton";
image.style.cursor = "pointer";
image.alt = alt;
image.title = comment;
image.src = source;
image.onclick = onclick;
tb.appendChild(image);
}
}
function addIwButton()
{
// FIXME: change the icon, by one with Rh letter drawn on it.
addButton2("wpIw", "Interwiki", "Interwiki",
"http://upload.wikimedia.org/wikipedia/commons/a/af/Button_Fractur_OCR.png", add_interwiki);
}
$(document).ready(addIwButton);