MediaWiki:Common.js: Perbedaan antara revisi
Tampilan
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 - | 🧠 MIPPEDIA DATA - OMNI-SCRIPT PRO | ||
Features: Chaining, Translate, Toggle, Cleaner, Summary, | |||
Auto-Aging (NEW), Project Portal (NEW) | |||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 7: | Baris 9: | ||
var $descBox = $('#mip-auto-description'); | var $descBox = $('#mip-auto-description'); | ||
var $sourceInfo = $('#mip-source-info'); | var $sourceInfo = $('#mip-source-info'); | ||
var $portalLinks = $('#mip-portal-links'); | |||
var $projectPortal = $('#mip-project-portal'); | |||
if (!$descBox.length) return; | if (!$descBox.length) return; | ||
var pageTitle = mw.config.get('wgPageName'); | var pageTitle = mw.config.get('wgPageName'); | ||
var currentYear = 2026; // Tahun Sekarang sesuai sistem Mippedia | |||
var projects = [ | var projects = [ | ||
{ id: 'id', 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/', label: 'Bahasa Indonesia' }, | ||
{ id: 'en', 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/', label: 'English Version' }, | ||
{ id: 'concise', 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/', label: 'Versi Ringkas' } | ||
]; | ]; | ||
// 🎂 Fitur 1: Auto-Aging (Hitung Umur Otomatis) | |||
function applyAutoAge(text) { | |||
return text.replace(/(\d{1,2}\s(?:Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember)\s(\d{4}))/gi, function(match, fullDate, year) { | |||
var age = currentYear - parseInt(year); | |||
return fullDate + " – usia " + age + " tahun"; | |||
}); | |||
} | |||
function cleanExtract(text) { | function cleanExtract(text) { | ||
| Baris 20: | Baris 35: | ||
} | } | ||
function applySummary(text) { | function applySummary(text) { | ||
var limit = 250; | var limit = 250; | ||
| Baris 42: | Baris 56: | ||
var sourceLink = p.base + encodeURIComponent(pageTitle); | var sourceLink = p.base + encodeURIComponent(pageTitle); | ||
// | // Terapkan Auto-Age sebelum ditampilin | ||
$descBox.html(applySummary( | var agedText = applyAutoAge(currentText); | ||
$descBox.html(applySummary(agedText)); | |||
var footer = '<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>'; | var footer = '<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>'; | ||
if (isTranslated) { | if (isTranslated) { | ||
| Baris 54: | Baris 69: | ||
$sourceInfo.html(footer); | $sourceInfo.html(footer); | ||
// | // 🚀 Fitur 3: Project Portal (Tombol Pindah Cepat) | ||
$portalLinks.empty(); | |||
projects.forEach(function(proj) { | |||
if (proj.id !== p.id) { | |||
$portalLinks.append('<a href="' + proj.base + encodeURIComponent(pageTitle) + '" target="_blank" style="font-size: 0.8em; color: #6a5acd; border: 1px solid #6a5acd; padding: 2px 8px; border-radius: 4px; text-decoration: none;">' + proj.label + '</a>'); | |||
} | |||
}); | |||
$projectPortal.fadeIn(); | |||
$(document).off('click', '.mip-read-btn').on('click', '.mip-read-btn', function() { | $(document).off('click', '.mip-read-btn').on('click', '.mip-read-btn', function() { | ||
$(this).hide(); $('.mip-dots').hide(); $('.mip-more').fadeIn(); | $(this).hide(); $('.mip-dots').hide(); $('.mip-more').fadeIn(); | ||
}); | }); | ||
if (isTranslated) { | if (isTranslated) { | ||
$(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { | $(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { | ||
if ($(this).text() === 'Tampilkan terjemahan') { | |||
renderAll(p, originalText, true, currentText); | |||
} else { | |||
renderAll(p, originalText, true, currentText); // Toggle logic | |||
} | |||
}); | }); | ||
} | } | ||
} | } | ||
| Baris 85: | Baris 98: | ||
$descBox.html('<div class="mip-loading-shimmer"></div>'); | $descBox.html('<div class="mip-loading-shimmer"></div>'); | ||
$sourceInfo.empty(); | $sourceInfo.empty(); | ||
$projectPortal.hide(); | |||
$descSection.show(); | $descSection.show(); | ||
| Baris 97: | Baris 111: | ||
var extract = cleanExtract(pages[pageId].extract); | var extract = cleanExtract(pages[pageId].extract); | ||
if (extract !== "") { | if (extract !== "") { | ||
if (p.id === 'en') { | if (p.id === 'en') { | ||
else { renderAll(p, extract, false); } | translateText(extract, function(translated) { renderAll(p, translated, true, extract); }); | ||
} else { renderAll(p, extract, false); } | |||
return; | return; | ||
} | } | ||
Revisi per 15 April 2026 00.16
/* ==========================================================
🧠 MIPPEDIA DATA - OMNI-SCRIPT PRO
Features: Chaining, Translate, Toggle, Cleaner, Summary,
Auto-Aging (NEW), Project Portal (NEW)
========================================================== */
(function() {
$(document).ready(function() {
var $descSection = $('#mip-desc-section');
var $descBox = $('#mip-auto-description');
var $sourceInfo = $('#mip-source-info');
var $portalLinks = $('#mip-portal-links');
var $projectPortal = $('#mip-project-portal');
if (!$descBox.length) return;
var pageTitle = mw.config.get('wgPageName');
var currentYear = 2026; // Tahun Sekarang sesuai sistem Mippedia
var projects = [
{ id: 'id', name: 'Mippedia bahasa Indonesia', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/', label: 'Bahasa Indonesia' },
{ id: 'en', name: 'Mippedia bahasa Inggris', url: 'https://en.mippedia.org/api.php', base: 'https://en.mippedia.org/wiki/', label: 'English Version' },
{ id: 'concise', name: 'Mippedia bahasa Indonesia ringkas', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/', label: 'Versi Ringkas' }
];
// 🎂 Fitur 1: Auto-Aging (Hitung Umur Otomatis)
function applyAutoAge(text) {
return text.replace(/(\d{1,2}\s(?:Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember)\s(\d{4}))/gi, function(match, fullDate, year) {
var age = currentYear - parseInt(year);
return fullDate + " – usia " + age + " tahun";
});
}
function cleanExtract(text) {
return text.replace(/\[\d+\]/g, '').replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim();
}
function applySummary(text) {
var limit = 250;
if (text.length <= limit) return '<span>' + text + '</span>';
return '<span>' + text.substring(0, limit) + '</span>' +
'<span class="mip-dots">... </span>' +
'<span class="mip-more" style="display:none;">' + text.substring(limit) + '</span>' +
'<span class="mip-read-btn" style="color: #6a5acd; cursor: pointer; font-weight: bold; margin-left: 5px;">Baca selengkapnya</span>';
}
function translateText(text, callback) {
var url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=id&dt=t&q=" + encodeURIComponent(text);
$.ajax({ url: url, success: function(res) {
var translated = "";
res[0].forEach(function(s) { if (s[0]) translated += s[0]; });
callback(translated);
}, error: function() { callback(text); } });
}
function renderAll(p, currentText, isTranslated, originalText) {
var sourceLink = p.base + encodeURIComponent(pageTitle);
// Terapkan Auto-Age sebelum ditampilin
var agedText = applyAutoAge(currentText);
$descBox.html(applySummary(agedText));
var footer = '<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>';
if (isTranslated) {
footer += '<br><span style="font-size: 0.85em; font-style: italic;">(Diterjemahkan secara otomatis)</span> ' +
'<span id="mip-toggle-orig" style="color: #6a5acd; cursor: pointer; text-decoration: underline; margin-left: 5px;">' + (currentText === originalText ? 'Tampilkan terjemahan' : 'Tampilkan versi asli') + '</span>';
}
footer += '</div>';
$sourceInfo.html(footer);
// 🚀 Fitur 3: Project Portal (Tombol Pindah Cepat)
$portalLinks.empty();
projects.forEach(function(proj) {
if (proj.id !== p.id) {
$portalLinks.append('<a href="' + proj.base + encodeURIComponent(pageTitle) + '" target="_blank" style="font-size: 0.8em; color: #6a5acd; border: 1px solid #6a5acd; padding: 2px 8px; border-radius: 4px; text-decoration: none;">' + proj.label + '</a>');
}
});
$projectPortal.fadeIn();
$(document).off('click', '.mip-read-btn').on('click', '.mip-read-btn', function() {
$(this).hide(); $('.mip-dots').hide(); $('.mip-more').fadeIn();
});
if (isTranslated) {
$(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() {
if ($(this).text() === 'Tampilkan terjemahan') {
renderAll(p, originalText, true, currentText);
} else {
renderAll(p, originalText, true, currentText); // Toggle logic
}
});
}
}
function fetchDescription(index) {
if (index >= projects.length) { $descSection.hide(); return; }
var p = projects[index];
$descBox.html('<div class="mip-loading-shimmer"></div>');
$sourceInfo.empty();
$projectPortal.hide();
$descSection.show();
$.ajax({
url: p.url,
data: { action: 'query', prop: 'extracts', exintro: true, explaintext: true, titles: pageTitle, format: 'json', origin: '*' },
dataType: 'json',
success: function(data) {
var pages = data.query.pages;
var pageId = Object.keys(pages)[0];
if (pageId != "-1") {
var extract = cleanExtract(pages[pageId].extract);
if (extract !== "") {
if (p.id === 'en') {
translateText(extract, function(translated) { renderAll(p, translated, true, extract); });
} else { renderAll(p, extract, false); }
return;
}
}
fetchDescription(index + 1);
},
error: function() { fetchDescription(index + 1); }
});
}
fetchDescription(0);
if ($('#mip-shimmer-style').length === 0) {
$('<style id="mip-shimmer-style">').text(`
.mip-loading-shimmer { height: 16px; width: 100%; background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); background-size: 200% 100%; animation: mip-shimmer 1.5s infinite; border-radius: 4px; }
@keyframes mip-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
`).appendTo('head');
}
});
})();