Utente:Jalo/vector.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
Nessun oggetto della modifica
Riga 46:
text = "{{Tradotto da|en|"+enArticle+"|"+dataOggi+"|id}}\n";
$('#wpTextbox1').textSelection('encapsulateSelection', { pre: text });
}
 
// TRADUCI WIKILINK DALL'INGLESE
function tradLink()
{
var toTrad = mw.html.escape($('#wpTextbox1').textSelection('getSelection'));
var trad ="";
$.getJSON("http://en.wikipedia.org/w/api.php?callback=?",
{
action: "query",
prop: "langlinks",
lllang: "it",
titles: toTrad,
format: "json",
redirects: ""
},
function(data) {
selStart = document.getElementById('wpTextbox1').selectionStart;
selEnd = document.getElementById('wpTextbox1').selectionEnd;
if (typeof(data)!="undefined" &&
typeof(data.query)!="undefined" &&
typeof(data.query.pages)!="undefined")
{
for (var key in data.query.pages) {
if (typeof(data.query.pages[key])!="undefined" &&
typeof(data.query.pages[key].langlinks)!="undefined" &&
typeof(data.query.pages[key].langlinks[0])!="undefined" &&
typeof(data.query.pages[key].langlinks[0]["*"])!="undefined")
{
trad = data.query.pages[key].langlinks[0]["*"];
try {
mw.html.escape($('#wpTextbox1').textSelection('encapsulateSelection', { pre: trad + "[", post: "]" }));
} catch (err) {}
document.getElementById('wpTextbox1').selectionStart = selStart + trad.length;
document.getElementById('wpTextbox1').selectionEnd = selEnd + trad.length + 2;
 
return;
}
}
}
try {
mw.html.escape($('#wpTextbox1').textSelection('encapsulateSelection', { pre: "", post: "[NO LINK]" }));
} catch (err) {}
document.getElementById('wpTextbox1').selectionStart = selEnd;
document.getElementById('wpTextbox1').selectionEnd = selEnd + 9;
});
}
 
Riga 173 ⟶ 127:
post: ''
}
};
gadgetTbBase.addButton(button);
 
button = {
id: 'Traduci link',
group: 'altro',
hotkey: 'W',
icon: '//upload.wikimedia.org/wikipedia/it/d/dc/Pulsante_small.png',
execute: tradLink
};
gadgetTbBase.addButton(button);
Riga 224 ⟶ 169:
gadgetTbBase.addButton(button);
}
 
importScript('MediaWiki:Gadget-tradLink.js');
 
//test