Jump to content

MediaWiki:Common.js

From Tidur Ragnarok Online Wiki
Revision as of 02:05, 7 September 2026 by TidurWikiAdmin (talk | contribs) (automated content update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.
// Live server stats widget + NPC-of-the-day spotlight for the wiki Main Page.
// Fetches a same-origin static JSON snapshot (regenerated every minute by
// a server cron job) - no external API/CORS needed.
$(function () {
	var $stats = $('#tro-live-stats');
	if ($stats.length) {
		$.getJSON('/tro-stats.json?_=' + Date.now())
			.done(function (data) {
				var order = ['Thrymora', 'Draevor', 'Aelgard'];
				var html = '<div class="tro-card-grid">';
				order.forEach(function (name) {
					var w = data.worlds[name];
					if (!w) return;
					var badgeClass = name === 'Thrymora' ? 'tro-badge-high' : (name === 'Draevor' ? 'tro-badge-mid' : 'tro-badge-low');
					html += '<div class="tro-card tro-live-card">' +
						'<span class="tro-badge ' + badgeClass + '">' + w.tier + '</span>' +
						'<span class="tro-card-title" style="margin-top:10px;">' + name + '</span>' +
						'<div class="tro-live-stat-row"><span>Online</span><b>' + (w.online === null ? '—' : w.online) + '</b></div>' +
						'<div class="tro-live-stat-row"><span>Top Adventurer</span><b>' + (w.top_char || '—') + (w.top_level ? ' (Lv.' + w.top_level + ')' : '') + '</b></div>' +
						'<div class="tro-live-stat-row"><span>Rate</span><b>' + w.rate + '</b></div>' +
						'</div>';
				});
				html += '</div>';
				$stats.html(html);
			})
			.fail(function () {
				$stats.html('<p style="color:var(--tro-ink-faint,#888);">Live stats are temporarily unavailable.</p>');
			});
	}

	// NPC-of-the-day spotlight - deterministic pick based on the calendar
	// day, so it's the same all day and rotates daily without needing a
	// server-side cron for this part.
	var $spotlight = $('#tro-npc-spotlight');
	if ($spotlight.length) {
		var npcs = [
			['World Guide', 'Auto-detects which of the 3 worlds you\'re on and explains what makes it different.'],
			['Poring Coins', 'Aelgard-exclusive: every monster has a small chance to drop a bonus coin, tradeable for classic rewards.'],
			['Fortune\'s Favor', 'Draevor-exclusive periodic world blessing shrine.'],
			['Daily Jobs', 'Repeatable kill tasks for a steady zeny top-up, twice a day.'],
			['Battle Coordinator', 'Practice PvP against a squad of trained opponents - solo or with backup allies.'],
			['Card Recycler', 'Trade in unwanted classic cards for something more useful.'],
			['Kill Contracts', 'Pick a race and difficulty, get a bounty target, collect the reward.'],
			['Global Auction House', 'A player-run auction house for rare finds.'],
			['Ranking Hub', 'The server\'s Hall of Fame - top characters and guilds.'],
			['Achievement System', 'Long-term goals and titles to chase.']
		];
		var dayIndex = Math.floor(Date.now() / 86400000) % npcs.length;
		var pick = npcs[dayIndex];
		var href = mw.util.getUrl(pick[0]);
		$spotlight.html(
			'<div class="tro-card" style="max-width:420px;margin:0 auto;">' +
			'<span class="tro-card-icon">✨</span>' +
			'<span class="tro-card-title">Today\'s Spotlight: <a href="' + href + '">' + pick[0] + '</a></span>' +
			'<span class="tro-card-desc">' + pick[1] + '</span>' +
			'</div>'
		);
	}
});