User:Jeeputer/PCBIndicator.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. |
![]() | This user script seems to have a documentation page at User:Jeeputer/PCBIndicator. |
// Fork of [[User:Jeeputer/defconIndicator.js]] (Which is
// itself a fork of [[User:Enterprisey/watchlist-notice.js]])
// to show Pending Changes Backlog icon on
// top of the page, next to the notification icon
mw.loader.using('mediawiki.util', function() {
var showPCB = function(icon, level, numPages) {
$('#pt-notifications-notice').after(
$('<li>')
.append(
$('<span>')
.css({
'font-size': '80%'
})
.text('PCB:')
.attr({
'title': 'Pending Changes Backlog'
})
)
.append(
$('<img width="20" height="20" style="cursor:pointer;" title="Pending Changes Backlog level: ' +
level + '; Click to update!">')
.css({
'padding': '0.25em 0.45em 0.2em',
'cursor': 'pointer'
})
.attr('src',
'/media/wikipedia/commons/' +
icon)
.click(updatePCB)
)
.append(
$('<span id="pcb-numpages">')
.css({
'font-size': '80%'
})
.text(numPages + ' page' + (parseInt(numPages) == 1 ? '' : 's'))
)
.css({
'opacity': '1',
'transition': 'opacity 0.5s'
})
.attr('id', 'pcb-indicator')
);
};
var changeIcon = function(icon, level, numPages) {
$('#pcb-indicator img').attr(
'src',
'/media/wikipedia/commons/' +
icon,
'title', 'Pending Changes Backlog: ' + level + '; Click to update!'
);
$('#pcb-numpages').text(numPages + ' page' + (parseInt(numPages) == 1 ? '' : 's'))
$('#pcb-indicator').css('opacity', '1');
};
var updatePCB = function() {
$('#pcb-indicator').css('opacity', '0');
$.getJSON(
mw.util.wikiScript('api'), {
format: 'json',
action: 'parse',
page: 'User:DatBot/pendingbacklog',
prop: 'wikitext'
}).done(function(data) {
var colors = {
'1': '6/6d/Ledred.png',
'2': '8/80/Ledorange.png',
'3': '0/0a/Ledyellow.png',
'4': '5/58/Ledgreen.png',
'5': '7/71/Ledblue.png'
};
var wikitext = data.parse.wikitext['*'];
var level = wikitext.match(/\|\s*level\s*\=\s*([0-9])/)[1];
var numPages = wikitext.match(/\|\s*info\s*\=\s*([0-9]*)/)[1];
if (level) {
var icon = colors[level];
if (!$('#pcb-indicator').length) {
showPCB(icon, level, numPages);
} else {
changeIcon(icon, level, numPages);
}
} else {
mw.notify($('<span>Looks like the wikitext at the ' +
'<a href="/wiki/User:DatBot/pendingbacklog">pendingbacklog page</a> ' +
'has been changed so the script cannot find the level.</span>'
), {
type: 'error',
autoHide: 'false',
tag: 'pcb-error'
});
}
});
};
$(document).ready(function() {
updatePCB();
window.setInterval(updatePCB, 120000);
});
});