MediaWiki:Common.js
MediaWiki interface page
More actions
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */// Load DataTables library
mw.hook('wikipage.content').add(function ($content) {
$content.find('.spoiler').on('click', function () {
$(this).toggleClass('revealed');
});
});
// Auto-embed X/Twitter status links into live tweets (no extension required)
(function () {
'use strict';
// Options you can tweak
var TW_OPTIONS = {
// theme: 'dark', // uncomment for dark
// conversation: 'none', // hide reply thread
// dnt: true, // "Do Not Track"
// align: 'center' // center the embed
};
function loadXWidgets (cb) {
// If the widget API is ready, go
if (window.twttr && twttr.widgets) { cb(); return; }
// Already loading?
if (document.querySelector('script[src*="platform.twitter.com/widgets.js"]')) {
// Poll until ready
var tries = 0, t = setInterval(function () {
if (window.twttr && twttr.widgets) { clearInterval(t); cb(); }
else if (++tries > 40) { clearInterval(t); }
}, 250);
return;
}
// Inject the widgets.js script
var s = document.createElement('script');
s.async = true;
s.src = 'https://platform.twitter.com/widgets.js';
s.onload = function () { cb(); };
document.head.appendChild(s);
}
// Find eligible links and embed them
function embedLinks(root) {
var scope = root || document;
var selector = [
'a[href^="https://x.com/"][href*="/status/"]',
'a[href^="http://x.com/"][href*="/status/"]',
'a[href^="https://twitter.com/"][href*="/status/"]',
'a[href^="http://twitter.com/"][href*="/status/"]'
].join(',');
var anchors = scope.querySelectorAll(selector);
if (!anchors.length) return;
loadXWidgets(function () {
anchors.forEach(function (a) {
if (a.dataset.tweetEmbedded === '1') return; // avoid duplicates
a.dataset.tweetEmbedded = '1';
// Extract the numeric tweet ID
var match = a.href.match(/\/status\/(\d+)/);
if (!match) return;
var id = match[1];
// Create a container after the link
var container = document.createElement('div');
container.className = 'tweet-embed';
a.insertAdjacentElement('afterend', container);
// Ask widgets API to render
if (window.twttr && twttr.widgets && twttr.widgets.createTweet) {
twttr.widgets.createTweet(id, container, TW_OPTIONS).catch(function(){});
}
});
// Ensure any dynamically added blockquotes also render
if (window.twttr && twttr.widgets && twttr.widgets.load) {
twttr.widgets.load(scope);
}
});
}
// Run on page load and whenever VE/LQT/etc. inject content
if (window.mw && mw.hook) {
mw.hook('wikipage.content').add(function ($content) {
embedLinks($content && $content[0]);
});
} else {
document.addEventListener('DOMContentLoaded', function () { embedLinks(document); });
}
})();
/* ===========================
Dungeon Leaderboard Script
=========================== */
mw.hook('wikipage.content').add(function () {
// ONLY run on Dungeon Leaderboard page
if (mw.config.get('wgPageName') !== "Dungeon_Leaderboard") return;
const table = document.getElementById("leaderboardTable");
if (!table) return;
const container = document.getElementById("filterContainer");
if (!container) return;
/* ---------- CREATE FILTER UI ---------- */
const wrapper = document.createElement("div");
wrapper.style.marginBottom = "15px";
const dungeonLabel = document.createElement("strong");
dungeonLabel.innerText = "Dungeon: ";
wrapper.appendChild(dungeonLabel);
const dungeonSelect = document.createElement("select");
dungeonSelect.style.marginRight = "20px";
const dungeons = [
"All",
"Wolf's Den",
"Wolf's Den II",
"Wolf's Den III",
"The Red Nest",
"For The Eggs",
"Scarlet Revenge",
"Scarlet Revenge II",
"Promised One",
"Promised One II",
"Promised One III",
"Lost and Found",
"The Hostage",
"Cactus On Fire",
"Deep Echoes",
"Deep Echoes II",
"Deep Echoes III"
];
dungeons.forEach(name => {
const option = document.createElement("option");
option.value = name;
option.textContent = name;
dungeonSelect.appendChild(option);
});
wrapper.appendChild(dungeonSelect);
const playerLabel = document.createElement("strong");
playerLabel.innerText = "Player: ";
wrapper.appendChild(playerLabel);
const playerInput = document.createElement("input");
playerInput.type = "text";
playerInput.placeholder = "Search player name...";
playerInput.style.padding = "4px";
wrapper.appendChild(playerInput);
container.appendChild(wrapper);
/* ---------- UTILITIES ---------- */
function parseTime(t) {
if (!t || !t.includes(":")) return 999999;
const parts = t.trim().split(":");
return parseInt(parts[0], 10) * 60 + parseInt(parts[1], 10);
}
function sortAndRank() {
const rows = Array.from(table.querySelectorAll("tr")).slice(1);
rows.sort((a, b) =>
parseTime(a.cells[4].innerText) -
parseTime(b.cells[4].innerText)
);
rows.forEach(row => table.appendChild(row));
let visibleIndex = 0;
rows.forEach(row => {
if (row.style.display === "none") return;
const rankCell = row.cells[0];
if (visibleIndex === 0) rankCell.innerHTML = "🥇 1";
else if (visibleIndex === 1) rankCell.innerHTML = "🥈 2";
else if (visibleIndex === 2) rankCell.innerHTML = "🥉 3";
else rankCell.innerText = visibleIndex + 1;
visibleIndex++;
});
}
function filterTable() {
const selectedDungeon = dungeonSelect.value;
const playerSearch = playerInput.value.toLowerCase();
const rows = Array.from(table.querySelectorAll("tr")).slice(1);
rows.forEach(row => {
const dungeon = row.cells[1].innerText.trim();
const player = row.cells[2].innerText.toLowerCase();
const dungeonMatch =
selectedDungeon === "All" || dungeon === selectedDungeon;
const playerMatch =
player.includes(playerSearch);
row.style.display =
(dungeonMatch && playerMatch) ? "" : "none";
});
sortAndRank();
}
dungeonSelect.addEventListener("change", filterTable);
playerInput.addEventListener("input", filterTable);
sortAndRank();
});