MediaWiki:Common.js: differenze tra le versioni
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
Riga 19: | Riga 19: | ||
text: 'Traduci Pagina', | text: 'Traduci Pagina', | ||
id: 'translate-page-link', | id: 'translate-page-link', | ||
click: function(event) { | click: function(event) { | ||
event.preventDefault(); | event.preventDefault(); | ||
Riga 32: | Riga 31: | ||
var pViews = $('#p-views ul'); | var pViews = $('#p-views ul'); | ||
if (pViews.length) { | if (pViews.length) { | ||
$('<li>').append(translateLink). | var firstListItem = pViews.children().first(); | ||
console.log("Translate link added to p-views"); | $('<li>').append(translateLink).insertBefore(firstListItem); | ||
console.log("Translate link added to p-views before first item"); | |||
} else { | } else { | ||
console.log("p-views not found"); | console.log("p-views not found"); |
Versione delle 13:26, 3 lug 2024
/* Any JavaScript here will be loaded for all users on every page load. */ console.error('TEST EX') // CODICE PER IL TRANSLATE BUTTON mw.loader.using('mediawiki.util', function() { console.log("Common.js is loaded"); $(document).ready(function() { console.log("DOM fully loaded and parsed"); // Ottieni la lingua del browser var userLang = navigator.language || navigator.userLanguage; var targetLanguage = userLang.split('-')[0]; // Prendi solo la parte principale della lingua (es. "it" da "it-IT") // Crea il collegamento per la traduzione var translateLink = $('<a>', { href: '#', text: 'Traduci Pagina', id: 'translate-page-link', click: function(event) { event.preventDefault(); var currentUrl = window.location.href; var translateUrl = "https://translate.google.com/translate?hl=&sl=auto&tl=" + targetLanguage + "&u=" + encodeURIComponent(currentUrl); window.open(translateUrl, '_blank'); console.log("Link clicked, translating to: " + targetLanguage); } }); // Trova la barra degli strumenti superiore e aggiungi il nuovo collegamento var pViews = $('#p-views ul'); if (pViews.length) { var firstListItem = pViews.children().first(); $('<li>').append(translateLink).insertBefore(firstListItem); console.log("Translate link added to p-views before first item"); } else { console.log("p-views not found"); } }); });