MediaWiki:Common.js: Perbedaan antara revisi
Tidak ada ringkasan suntingan Tanda: Pengembalian manual Suntingan perangkat seluler Suntingan peramban seluler |
Tidak ada ringkasan suntingan Tanda: Suntingan perangkat seluler Suntingan peramban seluler |
||
| Baris 1: | Baris 1: | ||
/* ========================================================== | /* ========================================================== | ||
🧠 MIPPEDIA DATA | 🧠 MIPPEDIA DATA - CORE ENGINE (FINAL STABLE) | ||
Fitur: Chaining (ID > EN > Concise) + Auto-Translate + Toggle Original | |||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 17: | Baris 17: | ||
]; | ]; | ||
// Fungsi pembersih sitasi [1], [2], dll agar terlihat profesional | |||
function cleanExtract(text) { | function cleanExtract(text) { | ||
return text.replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim(); | return text.replace(/\[\d+\]/g, '') // Hapus sitasi [1] | ||
.replace(/\{\{[^}]+\}\}/g, '') // Hapus template | |||
.replace(/\(\s*\)/g, '') // Hapus kurung kosong | |||
.replace(/\s\s+/g, ' ') // Hapus spasi ganda | |||
.trim(); | |||
} | } | ||
| Baris 27: | Baris 32: | ||
success: function(res) { | success: function(res) { | ||
var translated = ""; | var translated = ""; | ||
res[0].forEach(function(segment) { | res[0].forEach(function(segment) { if (segment[0]) translated += segment[0]; }); | ||
callback(translated); | callback(translated); | ||
}, | }, | ||
| Baris 56: | Baris 59: | ||
if (pageId != "-1") { | if (pageId != "-1") { | ||
var extract = cleanExtract(pages[pageId].extract); | var extract = cleanExtract(pages[pageId].extract); | ||
if (extract !== "") { | if (extract !== "") { | ||
var sourceLink = p.base + encodeURIComponent(pageTitle); | var sourceLink = p.base + encodeURIComponent(pageTitle); | ||
if (p.id === 'en') { | if (p.id === 'en') { | ||
translateText(extract, function(translated) { | translateText(extract, function(translated) { | ||
var | var html = | ||
'<div id="mip-text-content" style="margin-bottom: 12px;">' + translated + '</div>' + | '<div id="mip-text-content" style="margin-bottom: 12px;">' + translated + '</div>' + | ||
'<div style="font-size: 0.9em; color: #777;">' + | '<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>' + | '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> ' + | '<br><span style="font-size: 0.85em; font-style: italic;">(Diterjemahkan secara otomatis dari bahasa Inggris)</span> ' + | ||
'<span id="mip-toggle-orig" style="color: #6a5acd; cursor: pointer | '<span id="mip-toggle-orig" style="color: #6a5acd; cursor: pointer; text-decoration: underline; margin-left: 5px;">Tampilkan versi asli</span>' + | ||
'</div>'; | '</div>'; | ||
$descBox.hide().html(html).fadeIn(400); | |||
$descBox.hide().html( | |||
// Event | // Event Switch Text | ||
$(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { | $(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { | ||
var $content = $('#mip-text-content'); | var $content = $('#mip-text-content'); | ||
| Baris 85: | Baris 87: | ||
}); | }); | ||
} else { | } else { | ||
var html = | |||
var | |||
'<div style="margin-bottom: 12px;">' + extract + '</div>' + | '<div style="margin-bottom: 12px;">' + extract + '</div>' + | ||
'<div style="font-size: 0.9em; color: #777;">' + | '<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>' + | 'Sumber Dari : <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">' + p.name + '.</a>' + | ||
'</div>'; | '</div>'; | ||
$descBox.hide().html( | $descBox.hide().html(html).fadeIn(400); | ||
} | } | ||
return; | return; | ||