User:Equazcion/LagToMinutesBeta.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Equazcion/LagToMinutesBeta. |
// Debug mode: Set testSecs to desired test lag seconds. Should be a string in quotes with comma separator(s).
if (typeof testSecs == 'undefined') var testSecs = "621,139";
// Insert fake lag notice with test seconds value
if (wgPageName == 'Special:Watchlist') $('#contentSub').after('<div class="mw-lag-warn-high"><p>Due to high database server lag, changes newer than ' +
testSecs + ' seconds may not appear in this list.</p></div>');
// Script begins here
if ((wgPageName == 'Special:Watchlist') && ($('.mw-lag-warn-high').length > 0)) {
var lagText = $('.mw-lag-warn-high p').html();
var lagSecs = lagText.replace(/,/g , '').match(/\d+/g);
if (lagSecs >= 60){
var lagMin=0, lagHours=0, lagDays=0;
lagMin = Math.floor(lagSecs / 60);
lagSecs = lagSecs % 60;
var lagCount = lagMin + " minutes, " + lagSecs + " seconds";
if (lagMin >= 60){
lagHours = Math.floor(lagMin / 60);
lagMin = lagMin % 60;
lagCount = lagHours + " hours, " + lagMin + " minutes, " + lagSecs + " seconds";
if (lagHours >= 24){
lagDays = Math.floor(lagHours / 24);
lagHours = lagHours % 24;
lagCount = lagDays + " days, " + lagHours + " hours, " + lagMin + " minutes, " + lagSecs + " seconds";
}
}
if (lagMin == 1) lagCount = lagCount.replace('minutes','minute');
if (lagHours == 1) lagCount = lagCount.replace('hours','hour');
if (lagDays == 1) lagCount = lagCount.replace('days','day');
var newText = lagText.replace("seconds", "seconds (" + lagCount + ")");
$('.mw-lag-warn-high p').html(newText);
}
}