User:RCSDevs/author.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:RCSDevs/author. This user script seems to have an accompanying .css page at User:RCSDevs/author.css. |
importStylesheet('User:RCSDevs/author.css');
$(document).ready(function()
{
var tab = $('#ca-nstab-main');
if(tab.length && tab.attr('class') === 'selected')
{
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://wiki.riteme.site/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 dot format 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.filter(function(rev) { return !rev.user.includes('.') }).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);
$('#heart-icon').click(function()
{
var params = {
action: 'wikilove',
title: 'User:RCSDevs',//'User:' + username.replace(' ', '_'),
text: 'Your work has been noticed! Thanks for contributing to /wiki/' + title,
token: mw.user.tokens.get('editToken'),
type: 'barnstar-normal'
};
$.post('https://wiki.riteme.site/w/api.php', params);
});
});
}
});