MediaWiki:Common.js: Perbedaan antara revisi
Tampilan
Tidak ada ringkasan suntingan Tanda: Dikembalikan Suntingan perangkat seluler Suntingan peramban seluler |
Tidak ada ringkasan suntingan Tanda: Pengembalian manual Suntingan perangkat seluler Suntingan peramban seluler |
||
| Baris 1: | Baris 1: | ||
/* ========================================================== | /* ========================================================== | ||
🧠 MIPPEDIA DATA - | 🧠 MIPPEDIA DATA - ULTRA CLEAN SMART NAV (FINAL FIXED) | ||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
$(document).ready(function() { | $(document).ready(function() { | ||
var $descSection = $('#mip-desc-section'); | var $descSection = $('#mip-desc-section'); | ||
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 $portalLinks = $('#mip-portal-links'); | ||
var $projectPortal = $('#mip-project-portal'); | var $projectPortal = $('#mip-project-portal'); | ||
if (!$descBox.length) return; | if (!$descBox.length) return; | ||
| Baris 24: | Baris 21: | ||
]; | ]; | ||
function applyAutoAge(text) { | |||
function | 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) { | ||
return fullDate + " – usia " + (currentYear - parseInt(year)) + " 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>'; | |||
} | |||
// FUNGSI CERDAS: Cek ketersediaan artikel di wiki lain | |||
function buildSmartLinks(currentId) { | function buildSmartLinks(currentId) { | ||
$portalLinks.empty(); | $portalLinks.empty(); | ||
var validLinks = []; | var validLinks = []; | ||
var checkRequests = projects.filter(p => p.id !== currentId).map(function(p) { | var checkRequests = projects.filter(p => p.id !== currentId).map(function(p) { | ||
return $.ajax({ url: p.url, data: { action: 'query', titles: pageTitle, format: 'json', origin: '*' }, dataType: 'json' }) | return $.ajax({ | ||
url: p.url, | |||
data: { action: 'query', titles: pageTitle, format: 'json', origin: '*' }, | |||
dataType: 'json' | |||
}).then(function(data) { | |||
if (data.query.pages["-1"] === undefined) { | |||
validLinks.push('<a href="' + p.base + encodeURIComponent(pageTitle) + '" target="_blank" style="color: #6a5acd; text-decoration: underline; font-weight: bold;">' + p.label + '</a>'); | |||
} | |||
}); | |||
}); | }); | ||
$.when.apply($, checkRequests).done(function() { | $.when.apply($, checkRequests).done(function() { | ||
if (validLinks.length > 0) { $portalLinks.html(validLinks.join(' <span style="color:#ccc; margin: 0 5px;">•</span> ')); $projectPortal. | if (validLinks.length > 0) { | ||
$portalLinks.html(validLinks.join(' <span style="color:#ccc; margin: 0 5px;">•</span> ')); | |||
$projectPortal.show(); | |||
} else { | |||
$projectPortal.hide(); | |||
} | |||
}); | }); | ||
} | |||
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) { | function renderAll(p, currentText, isTranslated, originalText) { | ||
var sourceLink = p.base + encodeURIComponent(pageTitle); | |||
$descBox.html(applySummary(applyAutoAge(currentText))); | |||
$descBox | |||
var footer = '<div style="font-size: 0.9em; color: #777;">Sumber Dari : <a href="' + | 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;">Tampilkan versi asli</span>'; } | if (isTranslated) { | ||
$sourceInfo | 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;">Tampilkan versi asli</span>'; | |||
} | |||
footer += '</div>'; | |||
$sourceInfo.html(footer); | |||
buildSmartLinks(p.id); | buildSmartLinks(p.id); | ||
$(document).off('click', '.mip-read-btn').on('click', '.mip-read-btn', function() { $(this).hide(); $('.mip-dots').hide(); $('.mip-more').fadeIn(); }); | |||
$(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { var isOrig = ($(this).text() === 'Tampilkan versi asli'); $descBox.html(applySummary(applyAutoAge(isOrig ? originalText : currentText))); $(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli'); }); | $(document).off('click', '.mip-read-btn').on('click', '.mip-read-btn', function() { | ||
$(this).hide(); $('.mip-dots').hide(); $('.mip-more').fadeIn(); | |||
}); | |||
$(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { | |||
var isOrig = ($(this).text() === 'Tampilkan versi asli'); | |||
$descBox.html(applySummary(applyAutoAge(isOrig ? originalText : currentText))); | |||
$(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli'); | |||
}); | |||
} | } | ||
function fetchDescription(index) { | function fetchDescription(index) { | ||
if (index >= projects.length) { | if (index >= projects.length) { $descSection.hide(); return; } | ||
var p = projects[index]; | var p = projects[index]; | ||
$descBox.html('<div class="mip-loading-shimmer"></div>'); | |||
$sourceInfo.empty(); | |||
$projectPortal.hide(); | |||
$descSection.show(); | $descSection.show(); | ||
| Baris 83: | Baris 120: | ||
if (extract !== "") { | if (extract !== "") { | ||
if (p.id === 'en') { | if (p.id === 'en') { | ||
translateText(extract, function(trans) { renderAll(p, trans, true, extract); }); | |||
} else { renderAll(p, extract, false); } | } else { renderAll(p, extract, false); } | ||
return; | return; | ||
| Baris 92: | Baris 126: | ||
} | } | ||
fetchDescription(index + 1); | fetchDescription(index + 1); | ||
} | |||
}); | }); | ||
} | } | ||
Revisi per 15 April 2026 05.55
/* ==========================================================
🧠 MIPPEDIA DATA - ULTRA CLEAN SMART NAV (FINAL FIXED)
========================================================== */
(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;
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: 'Bahasa Inggris' },
{ id: 'concise', name: 'Mippedia bahasa Indonesia ringkas', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/', label: 'Versi Ringkas' }
];
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) {
return fullDate + " – usia " + (currentYear - parseInt(year)) + " 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>';
}
// FUNGSI CERDAS: Cek ketersediaan artikel di wiki lain
function buildSmartLinks(currentId) {
$portalLinks.empty();
var validLinks = [];
var checkRequests = projects.filter(p => p.id !== currentId).map(function(p) {
return $.ajax({
url: p.url,
data: { action: 'query', titles: pageTitle, format: 'json', origin: '*' },
dataType: 'json'
}).then(function(data) {
if (data.query.pages["-1"] === undefined) {
validLinks.push('<a href="' + p.base + encodeURIComponent(pageTitle) + '" target="_blank" style="color: #6a5acd; text-decoration: underline; font-weight: bold;">' + p.label + '</a>');
}
});
});
$.when.apply($, checkRequests).done(function() {
if (validLinks.length > 0) {
$portalLinks.html(validLinks.join(' <span style="color:#ccc; margin: 0 5px;">•</span> '));
$projectPortal.show();
} else {
$projectPortal.hide();
}
});
}
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);
$descBox.html(applySummary(applyAutoAge(currentText)));
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;">Tampilkan versi asli</span>';
}
footer += '</div>';
$sourceInfo.html(footer);
buildSmartLinks(p.id);
$(document).off('click', '.mip-read-btn').on('click', '.mip-read-btn', function() {
$(this).hide(); $('.mip-dots').hide(); $('.mip-more').fadeIn();
});
$(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() {
var isOrig = ($(this).text() === 'Tampilkan versi asli');
$descBox.html(applySummary(applyAutoAge(isOrig ? originalText : currentText)));
$(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli');
});
}
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(trans) { renderAll(p, trans, true, extract); });
} else { renderAll(p, extract, false); }
return;
}
}
fetchDescription(index + 1);
}
});
}
fetchDescription(0);
});
})();