MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
Esportsamaze (talk | contribs) No edit summary |
Esportsamaze (talk | contribs) No edit summary |
||
| Line 172: | Line 172: | ||
$('.firstHeading').text(cleanTitle); | $('.firstHeading').text(cleanTitle); | ||
} | } | ||
}); | |||
/* ========================================================== | |||
LIVE UPDATE NOTIFIER (Secure Version) | |||
Checks every 60 seconds if the page has a newer revision. | |||
========================================================== */ | |||
$(document).ready(function() { | |||
// Only run on View mode | |||
if (mw.config.get('wgAction') !== 'view') return; | |||
var currentRevId = mw.config.get('wgCurRevisionId'); | |||
var pageTitle = mw.config.get('wgPageName'); | |||
function checkForUpdates() { | |||
new mw.Api().get({ | |||
action: 'query', | |||
prop: 'info', | |||
titles: pageTitle, | |||
indexpageids: 1 | |||
}).done(function(data) { | |||
var page = data.query.pages[data.query.pageids[0]]; | |||
// If server has a newer ID | |||
if (page.lastrevid > currentRevId) { | |||
showUpdateToast(); | |||
} | |||
}); | |||
} | |||
function showUpdateToast() { | |||
// Prevent duplicate buttons | |||
if ($('#update-notification').length > 0) return; | |||
// 1. Create the Button Safely (No raw HTML strings) | |||
var $icon = $('<i>').addClass('fa-solid fa-rotate').css('margin-right', '8px'); | |||
var $btn = $('<div>') | |||
.attr('id', 'update-notification') | |||
.text(' New updates available. Click to refresh.') | |||
.prepend($icon) | |||
.css({ | |||
'position': 'fixed', | |||
'bottom': '30px', | |||
'left': '50%', | |||
'transform': 'translateX(-50%)', | |||
'background-color': '#00509d', | |||
'color': 'white', | |||
'padding': '12px 25px', | |||
'border-radius': '50px', | |||
'cursor': 'pointer', | |||
'box-shadow': '0 4px 15px rgba(0,0,0,0.3)', | |||
'z-index': '9999', | |||
'font-family': 'sans-serif', | |||
'font-weight': 'bold', | |||
'display': 'flex', | |||
'align-items': 'center' | |||
}) | |||
.on('click', function() { | |||
location.reload(); | |||
}); | |||
// 2. Add to page with animation | |||
$('body').append($btn); | |||
$btn.hide().fadeIn(500).css('bottom', '30px'); | |||
} | |||
// Run check every 60 seconds | |||
setInterval(checkForUpdates, 60000); | |||
}); | }); | ||
Revision as of 12:01, 1 February 2026
/* Any JavaScript here will be loaded for all users on every page load. */
/* ==========================================================
REMOVE DECIMALS (.0) FROM CARGO TABLES
========================================================== */
$(document).ready(function() {
// Target only cells inside the auto-rank table
$('.auto-rank td').each(function() {
var text = $(this).text();
// If the text looks like a number ending in .0 (e.g., "93.0")
if (/^\d+\.0$/.test(text)) {
// Replace it with just the integer part
$(this).text(parseInt(text));
}
});
});
/* ==========================================================
INDIAN CURRENCY FORMATTER (₹ Symbol Version)
========================================================== */
$(document).ready(function() {
$('.indian-currency').each(function() {
// 1. Get text and clean it (Remove commas AND existing ₹ symbol)
var rawNum = $(this).text().trim().replace(/,/g, '').replace(/₹/g, '');
// 2. Convert to a real number
var number = parseFloat(rawNum);
// 3. Check if it's a valid number
if (!isNaN(number)) {
// 4. Format to Indian Style (en-IN) - Automatically adds ₹
var formatted = number.toLocaleString('en-IN', {
style: 'currency',
currency: 'INR',
maximumFractionDigits: 0
});
// 5. Apply directly (This keeps the ₹ symbol)
$(this).text(formatted);
}
});
});
/* ========================================================
UNIVERSAL FILTER SYSTEM (Centralized Logic)
======================================================== */
$(function() {
// MASTER FUNCTION: updates the entire wrapper based on current button states
function refreshWrapperState($wrapper) {
// 1. Get the current settings
var activeView = $wrapper.find('.filter-btn[data-filter-type^="view_mode"].active').attr('data-value') || 'overall';
var activeGroup = ($wrapper.find('.filter-btn[data-filter-type^="group_"].active').attr('data-value') || 'all').toString().trim();
var filterType = $wrapper.find('.filter-btn[data-filter-type^="view_mode"].active').attr('data-filter-type'); // e.g., view_mode_The Grind
// 2. Hide all Views (Overall & Matches), then Show the Active One
$wrapper.find('.filterable-content[data-type^="view_mode"]').hide();
// Find the specific view (e.g., Match 2 table)
// We use the filterType to ensure we don't accidentally grab a view from a different stage
var $activeTable = $wrapper.find('.filterable-content[data-type="' + filterType + '"][data-value="' + activeView + '"]');
$activeTable.fadeIn(100);
// 3. Apply Group Filter to the rows INSIDE the active table
// We target ANY row (tr) that has a data-value attribute
var $rows = $activeTable.find('tr[data-value]');
if (activeGroup === 'all') {
$rows.show();
} else {
$rows.each(function() {
var $row = $(this);
var rowGroup = ($row.attr('data-value') || "").toString().trim();
if (rowGroup === activeGroup) {
$row.show();
} else {
$row.hide();
}
});
}
}
// CLICK HANDLER
$(document).on('click', '.filter-btn', function() {
var $btn = $(this);
var filterType = $btn.attr('data-filter-type');
var value = $btn.attr('data-value');
// Visual Update (Active State)
$btn.siblings('.filter-btn').removeClass('active');
$btn.addClass('active');
// LOGIC A: MASTER STAGE (Big Tabs like "Round 1")
if (filterType.indexOf('master_stage') !== -1) {
$('.filterable-content[data-type="' + filterType + '"]').hide();
$('.filterable-content[data-type="' + filterType + '"][data-value="' + value + '"]').fadeIn(200);
// Optional: When switching stages, trigger a refresh on that stage's wrapper
var $newStage = $('.filterable-content[data-type="' + filterType + '"][data-value="' + value + '"]');
var $innerWrapper = $newStage.find('.standings-wrapper');
if ($innerWrapper.length) refreshWrapperState($innerWrapper);
// LOGIC B: STANDINGS FILTERS (View or Group)
} else {
// Just run the master refresh on the parent wrapper
var $wrapper = $btn.closest('.standings-wrapper');
refreshWrapperState($wrapper);
}
});
// AUTO-INIT
setTimeout(function() {
if (!$('.filter-btn[data-filter-type="master_stage_selector"].active').length) {
$('.filter-btn[data-filter-type="master_stage_selector"]').first().click();
}
}, 500);
});
/* ==========================================================
HORIZONTAL SCROLL FOR STANDINGS (Mouse Wheel)
========================================================== */
mw.loader.using(['jquery'], function () {
$(function() {
// Target the wrapper we created in the Lua module
$('.standings-wrapper').on('wheel', function(e) {
var container = $(this).get(0);
var delta = e.originalEvent.deltaY;
// Check if table is actually scrollable
if (container.scrollWidth > container.clientWidth) {
// If moving Right (Delta +) and not at end OR
// If moving Left (Delta -) and not at start
if ((delta > 0 && container.scrollLeft + container.clientWidth < container.scrollWidth) ||
(delta < 0 && container.scrollLeft > 0)) {
// Scroll the table horizontally
container.scrollLeft += delta;
// Stop the whole page from scrolling down while we do this
e.preventDefault();
}
}
});
});
});
/* Active Tier Filter Highlight */
$(function() {
var urlParams = new URLSearchParams(window.location.search);
var tier = urlParams.get('tier');
var $buttons = $('#tier-filters .filter-btn');
$buttons.removeClass('active');
if (tier) {
$('#tier-filters .filter-btn[data-tier="' + tier + '"]').addClass('active');
} else {
$buttons.first().addClass('active');
}
});
/* Clean up Team Page Titles (Removes BGMI/Teams/...) */
$(function() {
// Only run if we are on a page with a slash in the title
var pageTitle = mw.config.get('wgTitle');
if (pageTitle.indexOf('/') !== -1) {
// Get the last part (e.g. "GodLike Esports")
var cleanTitle = pageTitle.split('/').pop();
// Replace the H1 text safely
$('.firstHeading').text(cleanTitle);
}
});
/* ==========================================================
LIVE UPDATE NOTIFIER (Secure Version)
Checks every 60 seconds if the page has a newer revision.
========================================================== */
$(document).ready(function() {
// Only run on View mode
if (mw.config.get('wgAction') !== 'view') return;
var currentRevId = mw.config.get('wgCurRevisionId');
var pageTitle = mw.config.get('wgPageName');
function checkForUpdates() {
new mw.Api().get({
action: 'query',
prop: 'info',
titles: pageTitle,
indexpageids: 1
}).done(function(data) {
var page = data.query.pages[data.query.pageids[0]];
// If server has a newer ID
if (page.lastrevid > currentRevId) {
showUpdateToast();
}
});
}
function showUpdateToast() {
// Prevent duplicate buttons
if ($('#update-notification').length > 0) return;
// 1. Create the Button Safely (No raw HTML strings)
var $icon = $('<i>').addClass('fa-solid fa-rotate').css('margin-right', '8px');
var $btn = $('<div>')
.attr('id', 'update-notification')
.text(' New updates available. Click to refresh.')
.prepend($icon)
.css({
'position': 'fixed',
'bottom': '30px',
'left': '50%',
'transform': 'translateX(-50%)',
'background-color': '#00509d',
'color': 'white',
'padding': '12px 25px',
'border-radius': '50px',
'cursor': 'pointer',
'box-shadow': '0 4px 15px rgba(0,0,0,0.3)',
'z-index': '9999',
'font-family': 'sans-serif',
'font-weight': 'bold',
'display': 'flex',
'align-items': 'center'
})
.on('click', function() {
location.reload();
});
// 2. Add to page with animation
$('body').append($btn);
$btn.hide().fadeIn(500).css('bottom', '30px');
}
// Run check every 60 seconds
setInterval(checkForUpdates, 60000);
});