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 CONTEXT VERSION | |||
Features: Smart Sync, Auto-Age, Auto-Bold, Smart Links, | |||
NEW: Dynamic Context (Waktu Lokal & Penanda Tahun) | |||
========================================================== */ | |||
(function() { | (function() { | ||
$(document).ready(function() { | $(document).ready(function() { | ||
| Baris 8: | Baris 13: | ||
var pageTitle = mw.config.get('wgPageName').replace(/_/g, ' '), | var pageTitle = mw.config.get('wgPageName').replace(/_/g, ' '), | ||
cacheKey = ' | cacheKey = 'mip_smart_context_' + 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: 'Mippedia 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: 'Mippedia 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: 'Mippedia bahasa Indonesia ringkas' } | ||
]; | ]; | ||
// --- SEMUA FUNGSI AWAL | // --- SEMUA FUNGSI AWAL --- | ||
function applyAutoBold(text) { | 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 | |||
return text.replace(/(\d{1,2}\s(?:Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember)\s(\d{4}))/gi, function(m, f, y) { | // --- FITUR BARU: DYNAMIC CONTEXT & REFINED AGE --- | ||
function applyDynamicContext(text) { | |||
var date = new Date(); | |||
var hari = ["Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"]; | |||
var bulan = ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"]; | |||
var tglSkrg = hari[date.getDay()] + ", " + date.getDate() + " " + bulan[date.getMonth()] + " " + date.getFullYear(); | |||
return text | |||
// 1. Tambah tgl asli setelah kata "Hari ini" atau "Saat ini" | |||
.replace(/(hari ini|saat ini|sekarang)/gi, '$1 (' + tglSkrg + ')') | |||
// 2. Pendeteksi Usia (Fitur awal lo) | |||
.replace(/(\d{1,2}\s(?:Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember)\s(\d{4}))/gi, function(m, f, y) { | |||
return f + " <span style='color: #444; font-weight: bold;'>– usia " + (currentYear - parseInt(y)) + " tahun</span>"; | |||
}) | |||
// 3. Penanda Jarak Tahun (Misal: Sejak 2010 -> Sejak 2010 [16 thn lalu]) | |||
.replace(/(sejak|tahun)\s(\d{4})/gi, function(m, k, y) { | |||
var gap = currentYear - parseInt(y); | |||
if (gap > 0 && gap < 100) return k + " " + y + " <small style='color: #888;'>(" + gap + " thn lalu)</small>"; | |||
return m; | |||
}); | |||
} | } | ||
function applySummary(text) { | function applySummary(text) { | ||
var limit = 250; | var limit = 250; | ||
| Baris 33: | Baris 53: | ||
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>'; | 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 buildSmartLinks(currentId) { | function buildSmartLinks(currentId) { | ||
$portalLinks.empty(); | $portalLinks.empty(); | ||
| Baris 45: | Baris 66: | ||
} | } | ||
// --- SISTEM SMART CHECK --- | // --- SISTEM SMART CHECK (CEPAT & UPDATE) --- | ||
var cached = JSON.parse(localStorage.getItem(cacheKey) || "{}"); | var cached = JSON.parse(localStorage.getItem(cacheKey) || "{}"); | ||
function init() { | function init() { | ||
var pCheck = projects[Math.floor(Math.random() * projects.length)]; | var pCheck = projects[Math.floor(Math.random() * projects.length)]; | ||
$.ajax({ | $.ajax({ | ||
| Baris 58: | Baris 78: | ||
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"; | ||
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); | ||
} else { | } else { fetchFreshData(latestTS); } | ||
}, | }, | ||
error: function() { | error: function() { if (cached.content) renderAll(cached.p, cached.content, cached.isTrans, cached.orig); } | ||
}); | }); | ||
} | } | ||
| Baris 106: | Baris 119: | ||
function renderAll(p, currentText, isTranslated, originalText) { | function renderAll(p, currentText, isTranslated, originalText) { | ||
var processedText = applyAutoBold( | // Gabungkan semua proses teks (Bold + Context/Age) | ||
var processedText = applyAutoBold(applyDynamicContext(currentText)); | |||
$descSection.show(); | $descSection.show(); | ||
$descBox.show().html(applySummary(processedText)); | $descBox.show().html(applySummary(processedText)); | ||
| Baris 116: | Baris 131: | ||
buildSmartLinks(p.id); | buildSmartLinks(p.id); | ||
// | // 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( | var textToDisplay = applyAutoBold(applyDynamicContext(isOrig ? originalText : currentText)); | ||
$descBox.html(applySummary(textToDisplay)); | $descBox.html(applySummary(textToDisplay)); | ||
$(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli'); | $(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli'); | ||