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: | ||
(function() { | (function() { | ||
$(document).ready(function() { | $(document).ready(function() { | ||
| Baris 13: | Baris 8: | ||
var pageTitle = mw.config.get('wgPageName').replace(/_/g, ' '), | var pageTitle = mw.config.get('wgPageName').replace(/_/g, ' '), | ||
cacheKey = ' | cacheKey = 'mip_v4_thumb_' + pageTitle, now = new Date().getTime(), | ||
currentYear = 2026; | currentYear = 2026; | ||
var projects = [ | var projects = [ | ||
{ id: 'id', name: 'Mippedia bahasa Indonesia', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/', label: ' | { 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: ' | { 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: ' | { id: 'concise', name: 'Mippedia bahasa Indonesia ringkas', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/', label: 'Versi Ringkas' } | ||
]; | ]; | ||
// --- | // --- FUNGSI AWAL --- | ||
function applyAutoBold(text) { return text.replace(new RegExp('(' + pageTitle + ')', 'gi'), '<strong>$1</strong>'); } | function applyAutoBold(text) { return text.replace(new RegExp('(' + pageTitle + ')', 'gi'), '<strong>$1</strong>'); } | ||
function cleanExtract(text) { return text.replace(/\[\d+\]/g, '').replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim(); } | function cleanExtract(text) { return text.replace(/\[\d+\]/g, '').replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim(); } | ||
function applyDynamicContext(text) { | function applyDynamicContext(text) { | ||
var date = new Date() | var date = new Date(), bulan = ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"]; | ||
var tglSkrg = date.getDate() + " " + bulan[date.getMonth()] + " " + date.getFullYear(); | |||
return text.replace(/(hari ini|saat ini|sekarang)/gi, '$1 (' + tglSkrg + ')') | |||
var tglSkrg = | .replace(/(\d{1,2}\s(?:Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember)\s(\d{4}))/gi, (m, f, y) => f + " <b>– usia " + (currentYear - parseInt(y)) + " tahun</b>") | ||
.replace(/(sejak|tahun)\s(\d{4})/gi, (m, k, y) => { | |||
return text | |||
.replace(/(\d{1,2}\s(?:Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember)\s(\d{4}))/gi, | |||
.replace(/(sejak|tahun)\s(\d{4})/gi, | |||
var gap = currentYear - parseInt(y); | var gap = currentYear - parseInt(y); | ||
return (gap > 0 && gap < 100) ? k + " " + y + " <small style='color: #888;'>(" + gap + " thn lalu)</small>" : m; | |||
}); | }); | ||
} | } | ||
function applySummary(text) { | function applySummary(text) { | ||
var limit = 250; | var limit = 250; | ||
| Baris 54: | Baris 36: | ||
} | } | ||
// --- SISTEM SMART CHECK & THUMBNAIL --- | |||
// --- SISTEM SMART CHECK | |||
var cached = JSON.parse(localStorage.getItem(cacheKey) || "{}"); | var cached = JSON.parse(localStorage.getItem(cacheKey) || "{}"); | ||
| Baris 73: | Baris 43: | ||
$.ajax({ | $.ajax({ | ||
url: pCheck.url, | url: pCheck.url, | ||
data: { action: 'query', prop: 'revisions', rvprop: 'timestamp', titles: pageTitle, format: 'json', origin: '*' }, | data: { action: 'query', prop: 'revisions|pageimages', rvprop: 'timestamp', piprop: 'thumbnail', pithumbsize: 150, titles: pageTitle, format: 'json', origin: '*' }, | ||
dataType: 'json', | dataType: 'json', | ||
success: function(res) { | success: function(res) { | ||
var pg = res.query.pages, id = Object.keys(pg)[0]; | var pg = res.query.pages, id = Object.keys(pg)[0]; | ||
var latestTS = (id != "-1") ? pg[id].revisions[0].timestamp : "0"; | var latestTS = (id != "-1") ? pg[id].revisions[0].timestamp : "0"; | ||
var thumbUrl = (id != "-1" && pg[id].thumbnail) ? pg[id].thumbnail.source : ""; | |||
if (cached.content && cached.ts === latestTS) { | if (cached.content && cached.ts === latestTS) { | ||
renderAll(cached.p, cached.content, cached.isTrans, cached.orig); | renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img); | ||
} else { fetchFreshData(latestTS); } | } else { fetchFreshData(latestTS, thumbUrl); } | ||
}, | }, | ||
error: function() { if (cached.content) renderAll(cached.p, cached.content, cached.isTrans, cached.orig); } | error: function() { if (cached.content) renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img); } | ||
}); | }); | ||
} | } | ||
function fetchFreshData(newTS) { | function fetchFreshData(newTS, img) { | ||
var found = false | var found = false, shuffled = projects.sort(() => Math.random() - 0.5); | ||
shuffled.forEach(function(p) { | shuffled.forEach(function(p) { | ||
if (found) return; | if (found) return; | ||
| Baris 97: | Baris 68: | ||
success: function(data) { | success: function(data) { | ||
if (found) return; | if (found) return; | ||
var | var pg = data.query.pages, id = Object.keys(pg)[0]; | ||
if ( | if (id != "-1" && pg[id].extract) { | ||
found = true; | found = true; | ||
var | var ext = cleanExtract(pg[id].extract); | ||
if (p.id === 'en') { | if (p.id === 'en') { | ||
$. | $.get("https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=id&dt=t&q=" + encodeURIComponent(ext), function(tr) { | ||
var | var txt = ""; tr[0].forEach(s => { if (s[0]) txt += s[0]; }); | ||
finalize(p, | finalize(p, txt, true, ext, newTS, img); | ||
}); | |||
} else { finalize(p, | } else { finalize(p, ext, false, "", newTS, img); } | ||
} | } | ||
} | } | ||
| Baris 113: | Baris 84: | ||
} | } | ||
function finalize(p, c, t, o, ts) { | function finalize(p, c, t, o, ts, img) { | ||
localStorage.setItem(cacheKey, JSON.stringify({p:p, content:c, isTrans:t, orig:o, ts:ts})); | localStorage.setItem(cacheKey, JSON.stringify({p:p, content:c, isTrans:t, orig:o, ts:ts, img:img})); | ||
renderAll(p, c, t, o); | renderAll(p, c, t, o, img); | ||
} | } | ||
function renderAll(p, currentText, isTranslated, originalText) { | function renderAll(p, currentText, isTranslated, originalText, img) { | ||
var processedText = applyAutoBold(applyDynamicContext(currentText)); | var processedText = applyAutoBold(applyDynamicContext(currentText)); | ||
$descSection.show(); | |||
// Layouting Thumbnail (Hanya muncul jika img ada) | |||
var thumbHtml = img ? '<div style="float: right; margin-left: 15px; margin-bottom: 10px; border: 1px solid #ddd; padding: 3px; background: #fff; border-radius: 4px;"><img src="'+img+'" style="max-width: 100px; display: block;"></div>' : ''; | |||
$descBox.show().html(thumbHtml + applySummary(processedText) + '<div style="clear:both;"></div>'); | |||
$descBox.show().html(applySummary(processedText)); | |||
var footer = '<div style="font-size: 0. | var footer = '<div style="font-size: 0.85em; color: #777; margin-top: 10px;">Sumber Dari : <a href="' + p.base + encodeURIComponent(pageTitle) + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">' + p.name + '.</a>'; | ||
if (isTranslated) { footer += '<br><span | if (isTranslated) { footer += '<br><span>(Diterjemahkan otomatis)</span> <span id="mip-toggle-orig" style="color: #6a5acd; cursor: pointer; text-decoration: underline; margin-left: 5px;">Tampilkan versi asli</span>'; } | ||
$sourceInfo.show().html(footer); | $sourceInfo.show().html(footer); | ||
// Event Handlers | |||
// Handlers | |||
$(document).off('click', '.mip-read-btn').on('click', '.mip-read-btn', function() { $(this).hide(); $('.mip-dots').hide(); $('.mip-more').fadeIn(); }); | $(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() { | $(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { | ||
var isOrig = ($(this).text() === 'Tampilkan versi asli'); | var isOrig = ($(this).text() === 'Tampilkan versi asli'); | ||
var textToDisplay = applyAutoBold(applyDynamicContext(isOrig ? originalText : currentText)); | var textToDisplay = applyAutoBold(applyDynamicContext(isOrig ? originalText : currentText)); | ||
$descBox.html(applySummary(textToDisplay)); | $descBox.html(thumbHtml + applySummary(textToDisplay) + '<div style="clear:both;"></div>'); | ||
$(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli'); | $(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli'); | ||
}); | }); | ||
Revisi per 16 April 2026 09.02
(function() {
$(document).ready(function() {
var $descSection = $('#mip-desc-section'), $descBox = $('#mip-auto-description'),
$sourceInfo = $('#mip-source-info'), $portalLinks = $('#mip-portal-links'),
$projectPortal = $('#mip-project-portal');
if (!$descBox.length) return;
var pageTitle = mw.config.get('wgPageName').replace(/_/g, ' '),
cacheKey = 'mip_v4_thumb_' + pageTitle, now = new Date().getTime(),
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' }
];
// --- FUNGSI AWAL ---
function applyAutoBold(text) { return text.replace(new RegExp('(' + pageTitle + ')', 'gi'), '<strong>$1</strong>'); }
function cleanExtract(text) { return text.replace(/\[\d+\]/g, '').replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim(); }
function applyDynamicContext(text) {
var date = new Date(), bulan = ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"];
var tglSkrg = date.getDate() + " " + bulan[date.getMonth()] + " " + date.getFullYear();
return text.replace(/(hari ini|saat ini|sekarang)/gi, '$1 (' + tglSkrg + ')')
.replace(/(\d{1,2}\s(?:Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember)\s(\d{4}))/gi, (m, f, y) => f + " <b>– usia " + (currentYear - parseInt(y)) + " tahun</b>")
.replace(/(sejak|tahun)\s(\d{4})/gi, (m, k, y) => {
var gap = currentYear - parseInt(y);
return (gap > 0 && gap < 100) ? k + " " + y + " <small style='color: #888;'>(" + gap + " thn lalu)</small>" : m;
});
}
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>';
}
// --- SISTEM SMART CHECK & THUMBNAIL ---
var cached = JSON.parse(localStorage.getItem(cacheKey) || "{}");
function init() {
var pCheck = projects[Math.floor(Math.random() * projects.length)];
$.ajax({
url: pCheck.url,
data: { action: 'query', prop: 'revisions|pageimages', rvprop: 'timestamp', piprop: 'thumbnail', pithumbsize: 150, titles: pageTitle, format: 'json', origin: '*' },
dataType: 'json',
success: function(res) {
var pg = res.query.pages, id = Object.keys(pg)[0];
var latestTS = (id != "-1") ? pg[id].revisions[0].timestamp : "0";
var thumbUrl = (id != "-1" && pg[id].thumbnail) ? pg[id].thumbnail.source : "";
if (cached.content && cached.ts === latestTS) {
renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img);
} else { fetchFreshData(latestTS, thumbUrl); }
},
error: function() { if (cached.content) renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img); }
});
}
function fetchFreshData(newTS, img) {
var found = false, shuffled = projects.sort(() => Math.random() - 0.5);
shuffled.forEach(function(p) {
if (found) return;
$.ajax({
url: p.url,
data: { action: 'query', prop: 'extracts', exintro: 1, explaintext: 1, titles: pageTitle, format: 'json', origin: '*' },
dataType: 'json',
success: function(data) {
if (found) return;
var pg = data.query.pages, id = Object.keys(pg)[0];
if (id != "-1" && pg[id].extract) {
found = true;
var ext = cleanExtract(pg[id].extract);
if (p.id === 'en') {
$.get("https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=id&dt=t&q=" + encodeURIComponent(ext), function(tr) {
var txt = ""; tr[0].forEach(s => { if (s[0]) txt += s[0]; });
finalize(p, txt, true, ext, newTS, img);
});
} else { finalize(p, ext, false, "", newTS, img); }
}
}
});
});
}
function finalize(p, c, t, o, ts, img) {
localStorage.setItem(cacheKey, JSON.stringify({p:p, content:c, isTrans:t, orig:o, ts:ts, img:img}));
renderAll(p, c, t, o, img);
}
function renderAll(p, currentText, isTranslated, originalText, img) {
var processedText = applyAutoBold(applyDynamicContext(currentText));
$descSection.show();
// Layouting Thumbnail (Hanya muncul jika img ada)
var thumbHtml = img ? '<div style="float: right; margin-left: 15px; margin-bottom: 10px; border: 1px solid #ddd; padding: 3px; background: #fff; border-radius: 4px;"><img src="'+img+'" style="max-width: 100px; display: block;"></div>' : '';
$descBox.show().html(thumbHtml + applySummary(processedText) + '<div style="clear:both;"></div>');
var footer = '<div style="font-size: 0.85em; color: #777; margin-top: 10px;">Sumber Dari : <a href="' + p.base + encodeURIComponent(pageTitle) + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">' + p.name + '.</a>';
if (isTranslated) { footer += '<br><span>(Diterjemahkan otomatis)</span> <span id="mip-toggle-orig" style="color: #6a5acd; cursor: pointer; text-decoration: underline; margin-left: 5px;">Tampilkan versi asli</span>'; }
$sourceInfo.show().html(footer);
// Event Handlers
$(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');
var textToDisplay = applyAutoBold(applyDynamicContext(isOrig ? originalText : currentText));
$descBox.html(thumbHtml + applySummary(textToDisplay) + '<div style="clear:both;"></div>');
$(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli');
});
}
init();
});
})();