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 - ULTIMATE | 🧠 MIPPEDIA DATA - ULTIMATE RANDOMIZED VERSION | ||
Features: | Features: Randomized Source (NEW), Auto-Age, Smart Links, | ||
Auto-Bold Subject | Auto-Bold Subject, Double-Click Search | ||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 14: | Baris 14: | ||
if (!$descBox.length) return; | if (!$descBox.length) return; | ||
var pageTitle = mw.config.get('wgPageName').replace(/_/g, ' '); | var pageTitle = mw.config.get('wgPageName').replace(/_/g, ' '); | ||
var currentYear = 2026; | var currentYear = 2026; | ||
| Baris 23: | Baris 23: | ||
]; | ]; | ||
function applyAutoBold(text) { | function applyAutoBold(text) { | ||
var regex = new RegExp('(' + pageTitle + ')', 'gi'); | var regex = new RegExp('(' + pageTitle + ')', 'gi'); | ||
return text.replace(regex, '<strong>$1</strong>'); | return text.replace(regex, '<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(); } | ||
| Baris 58: | Baris 55: | ||
function renderAll(p, currentText, isTranslated, originalText) { | function renderAll(p, currentText, isTranslated, originalText) { | ||
var processedText = applyAutoBold(applyAutoAge(currentText)); | var processedText = applyAutoBold(applyAutoAge(currentText)); | ||
$descBox.show().html(applySummary(processedText)); | $descBox.show().html(applySummary(processedText)); | ||
var footer = '<div style="font-size: 0.9em; color: #777;">Sumber Dari : <a href="' + p.base + encodeURIComponent(pageTitle) + '" 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="' + p.base + encodeURIComponent(pageTitle) + '" 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) { 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>'; } | ||
$sourceInfo.show().html(footer); | $sourceInfo.show().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-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() { | ||
| Baris 78: | Baris 70: | ||
} | } | ||
function | // 🛠️ FUNGSI BARU: Cari data di semua proyek lalu acak | ||
function fetchRandomizedDescription() { | |||
var | var availableSources = []; | ||
var requests = projects.map(function(p) { | |||
return $.ajax({ | |||
url: p.url, | |||
data: { action: 'query', prop: 'extracts', exintro: true, explaintext: true, titles: pageTitle, format: 'json', origin: '*' }, | |||
dataType: 'json' | |||
}).then(function(data) { | |||
var pages = data.query.pages; | var pages = data.query.pages; | ||
var pageId = Object.keys(pages)[0]; | var pageId = Object.keys(pages)[0]; | ||
| Baris 93: | Baris 84: | ||
var extract = cleanExtract(pages[pageId].extract); | var extract = cleanExtract(pages[pageId].extract); | ||
if (extract !== "") { | if (extract !== "") { | ||
availableSources.push({ project: p, content: extract }); | |||
} | } | ||
} | } | ||
}); | |||
}); | |||
$.when.apply($, requests).always(function() { | |||
if (availableSources.length > 0) { | |||
$descSection.show(); | |||
// --- KOCOK SUMBER SECARA ACAK --- | |||
var randomIndex = Math.floor(Math.random() * availableSources.length); | |||
var selected = availableSources[randomIndex]; | |||
var p = selected.project; | |||
var extract = selected.content; | |||
if (p.id === 'en') { | |||
$.ajax({ url: "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=id&dt=t&q=" + encodeURIComponent(extract), success: function(res) { | |||
var trans = ""; res[0].forEach(function(s) { if (s[0]) trans += s[0]; }); | |||
renderAll(p, trans, true, extract); | |||
}}); | |||
} else { | |||
renderAll(p, extract, false); | |||
} | |||
} | |||
}); | }); | ||
} | } | ||
fetchRandomizedDescription(); | |||
}); | }); | ||
})(); | })(); | ||