MediaWiki:Common.js: Perbedaan antara revisi
Tidak ada ringkasan suntingan Tanda: Suntingan perangkat seluler Suntingan peramban seluler |
Tidak ada ringkasan suntingan Tanda: Suntingan perangkat seluler Suntingan peramban seluler |
||
| Baris 1: | Baris 1: | ||
/* ========================================================== | /* ========================================================== | ||
🧠 MIPPEDIA DATA SMART-FALLBACK | 🧠 MIPPEDIA DATA SMART-FALLBACK + AUTO-TRANSLATE | ||
- | Priority: ID -> EN (Auto-Translate) -> CONCISE | ||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 13: | Baris 12: | ||
var projects = [ | var projects = [ | ||
{ name: 'Mippedia bahasa Indonesia', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/' }, | { id: 'id', name: 'Mippedia bahasa Indonesia', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/' }, | ||
{ name: 'Mippedia bahasa Inggris', url: 'https://en.mippedia.org/api.php', base: 'https://en.mippedia.org/wiki/' }, | { id: 'en', name: 'Mippedia bahasa Inggris', url: 'https://en.mippedia.org/api.php', base: 'https://en.mippedia.org/wiki/' }, | ||
{ name: 'Mippedia bahasa Indonesia ringkas', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/' } | { id: 'concise', name: 'Mippedia bahasa Indonesia ringkas', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/' } | ||
]; | ]; | ||
function cleanExtract(text) { | function cleanExtract(text) { | ||
return text.replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim(); | return text.replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim(); | ||
} | |||
// Fungsi sakti buat nerjemahin teks secara otomatis | |||
function translateText(text, callback) { | |||
var translateUrl = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=id&dt=t&q=" + encodeURIComponent(text); | |||
$.ajax({ | |||
url: translateUrl, | |||
success: function(res) { | |||
var translated = ""; | |||
res[0].forEach(function(segment) { | |||
if (segment[0]) translated += segment[0]; | |||
}); | |||
callback(translated); | |||
}, | |||
error: function() { | |||
callback(text); // Jika gagal translate, balikin teks asli (Inggris) | |||
} | |||
}); | |||
} | } | ||
| Baris 46: | Baris 63: | ||
var sourceLink = p.base + encodeURIComponent(pageTitle); | var sourceLink = p.base + encodeURIComponent(pageTitle); | ||
// --- | // Logika khusus untuk Mippedia Inggris (Auto-Translate) | ||
var formattedContent = | if (p.id === 'en') { | ||
translateText(extract, function(translated) { | |||
var formattedContent = | |||
'<div style="margin-bottom: 12px;">' + translated + '</div>' + | |||
'<div style="font-size: 0.9em; color: #777;">' + | |||
'Sumber Dari : <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">' + p.name + '.</a>' + | |||
'<br><span style="font-size: 0.85em; font-style: italic;">(Diterjemahkan secara otomatis dari bahasa Inggris)</span>' + | |||
'</div>'; | |||
$descBox.hide().html(formattedContent).fadeIn(400); | |||
}); | |||
} else { | |||
// Untuk ID dan Concise (Normal) | |||
var formattedContent = | |||
'<div style="margin-bottom: 12px;">' + extract + '</div>' + | |||
'<div style="font-size: 0.9em; color: #777;">' + | |||
'Sumber Dari : <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">' + p.name + '.</a>' + | |||
'</div>'; | |||
$descBox.hide().html(formattedContent).fadeIn(400); | |||
} | |||
return; | return; | ||
} | } | ||
| Baris 67: | Baris 96: | ||
fetchDescription(0); | fetchDescription(0); | ||
if ($('#mip-shimmer-style').length === 0) { | if ($('#mip-shimmer-style').length === 0) { | ||
$('<style id="mip-shimmer-style">').text(` | $('<style id="mip-shimmer-style">').text(` | ||