User:RCSDevs/common.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. |
![]() | The accompanying .css page for this skin is at User:RCSDevs/common.css. |
importScript('User:RCSDevs/quiz.js');
$(document).ready(function()
{
var tab = $('#ca-nstab-main');
//Ensure the current page is an actual article
if(tab.length && tab.attr('class') === 'selected')
{
$('#heart-icon').click(function(event)
{
alert("Send wikilove api request to user");
});
var currentURL = decodeURIComponent(tab.find('span a').eq(0).attr('href')),
title = currentURL.substring(currentURL.indexOf('/wiki/') + 6);
//Define parameters for call to MediaWiki API (https://www.mediawiki.org/wiki/API)
var params = {
action: 'query',
prop: 'revisions',
rvprop: 'user',
rvlimit: 'max',
format: 'json',
titles: title
},
coordLabel = $('#coordinates');
//First checks if the article has a (redundent) coordinate label
if(coordLabel.length)
{
//For some reason .first() doesn't work
coordLabel.closest('tr').find('th').html('<a href="/wiki/Geographic_coordinate_system" title="Geographic coordinate system">Coordinates</a>');
coordLabel.parent().remove();
}
//Send request with JSON callback
$.getJSON('https://en.wikipedia.org/w/api.php', params, function(json)
{
var pages = json.query.pages,
revs = pages[Object.keys(pages)[0]].revisions, //Extract 'revisions' array. For some reason, normal JSON doesn't work
/* The following line:
1) Calculate occurances for all usernames in the revision list (the last 500 revisions)
2) Sort the array by decreasing occurances
3) Pull the top value and set 'username'
*/
username = revs.sort(function(a, b) { return revs.filter(function(x) { return x.user === b.user }).length - revs.filter(function(x) { return x.user === a.user }).length })[0].user,
//Construct an inline-styled message to add to page
message = '<div id="siteSub" style="float: right"><b><i>The main contributor to this article is </i><div id="pt-userpage" style="display: inline-block; background-position: left center"><strong style="color: #009500">' + username + '</strong><div id="heart-icon" title="Thank this user for their work!"></div></div></b></div>';
//Add message to article body
$('#siteSub').before(message);
});
}
});