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 SMART-FALLBACK (3-LAYER PRIORITY) | ||
Order: ID -> EN -> CONCISE | |||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 6: | Baris 7: | ||
var $descSection = $('#mip-desc-section'); | var $descSection = $('#mip-desc-section'); | ||
var $descBox = $('#mip-auto-description'); | var $descBox = $('#mip-auto-description'); | ||
if (!$descBox.length) return; | |||
var pageTitle = mw.config.get('wgPageName'); | |||
// Urutan prioritas proyek | |||
var projects = [ | |||
{ name: 'Mippedia bahasa Indonesia', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/' }, | |||
{ name: 'Mippedia bahasa Inggris', url: 'https://en.mippedia.org/api.php', base: 'https://en.mippedia.org/wiki/' }, | |||
{ name: 'Mippedia bahasa Indonesia ringkas', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/' } | |||
]; | |||
// Fungsi pembersihan teks | |||
function cleanExtract(text) { | |||
return text.replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim(); | |||
} | |||
// Fungsi utama untuk mengecek satu per satu | |||
function fetchDescription(index) { | |||
if (index >= projects.length) { | |||
// Jika sudah mentok di proyek terakhir dan tetap tidak ada | |||
$descSection.hide(); | |||
return; | |||
} | |||
var p = projects[index]; | |||
// Tampilkan animasi loading skeleton saat berpindah pencarian | |||
$descBox.html('<div class="mip-loading-shimmer"></div>'); | |||
$descSection.show(); | |||
$.ajax({ | $.ajax({ | ||
url: | url: p.url, | ||
data: { | data: { action: 'query', prop: 'extracts', exintro: true, explaintext: true, titles: pageTitle, format: 'json', origin: '*' }, | ||
dataType: 'json', | dataType: 'json', | ||
success: function(data) { | success: function(data) { | ||
| Baris 22: | Baris 45: | ||
var pageId = Object.keys(pages)[0]; | var pageId = Object.keys(pages)[0]; | ||
if (pageId != "-1") { | if (pageId != "-1") { | ||
var extract = pages[pageId].extract; | var extract = cleanExtract(pages[pageId].extract); | ||
if (extract !== "") { | if (extract !== "") { | ||
var sourceLink = | // JIKA KETEMU: Hentikan pencarian dan tampilkan | ||
var sourceLink = p.base + encodeURIComponent(pageTitle); | |||
$descBox.hide().html( | |||
$descBox.html( | |||
extract + | extract + | ||
' <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">Dari | ' <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">Dari ' + p.name + ' ↗️</a>' | ||
); | ).fadeIn(400); | ||
return; | |||
} | } | ||
} | } | ||
// JIKA | // JIKA TIDAK KETEMU: Lanjut ke proyek berikutnya di daftar | ||
fetchDescription(index + 1); | |||
}, | |||
error: function() { | |||
// Jika error (server down dsb), coba proyek selanjutnya | |||
fetchDescription(index + 1); | |||
} | } | ||
}); | }); | ||
} | } | ||
// Jalankan pencarian mulai dari index 0 (ID) | |||
fetchDescription(0); | |||
// Tambahkan CSS Loading Shimmer (Nomor 5) | |||
$('<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'); | |||
}); | }); | ||
})(); | })(); | ||
Revisi per 14 April 2026 22.38
/* ==========================================================
🧠 MIPPEDIA DATA SMART-FALLBACK (3-LAYER PRIORITY)
Order: ID -> EN -> CONCISE
========================================================== */
(function() {
$(document).ready(function() {
var $descSection = $('#mip-desc-section');
var $descBox = $('#mip-auto-description');
if (!$descBox.length) return;
var pageTitle = mw.config.get('wgPageName');
// Urutan prioritas proyek
var projects = [
{ name: 'Mippedia bahasa Indonesia', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/' },
{ name: 'Mippedia bahasa Inggris', url: 'https://en.mippedia.org/api.php', base: 'https://en.mippedia.org/wiki/' },
{ name: 'Mippedia bahasa Indonesia ringkas', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/' }
];
// Fungsi pembersihan teks
function cleanExtract(text) {
return text.replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim();
}
// Fungsi utama untuk mengecek satu per satu
function fetchDescription(index) {
if (index >= projects.length) {
// Jika sudah mentok di proyek terakhir dan tetap tidak ada
$descSection.hide();
return;
}
var p = projects[index];
// Tampilkan animasi loading skeleton saat berpindah pencarian
$descBox.html('<div class="mip-loading-shimmer"></div>');
$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 !== "") {
// JIKA KETEMU: Hentikan pencarian dan tampilkan
var sourceLink = p.base + encodeURIComponent(pageTitle);
$descBox.hide().html(
extract +
' <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">Dari ' + p.name + ' ↗️</a>'
).fadeIn(400);
return;
}
}
// JIKA TIDAK KETEMU: Lanjut ke proyek berikutnya di daftar
fetchDescription(index + 1);
},
error: function() {
// Jika error (server down dsb), coba proyek selanjutnya
fetchDescription(index + 1);
}
});
}
// Jalankan pencarian mulai dari index 0 (ID)
fetchDescription(0);
// Tambahkan CSS Loading Shimmer (Nomor 5)
$('<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');
});
})();