User:Euphoria/common.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
Line 52: | Line 52: | ||
.append($('<a>').attr('href', wikiURL + '/wiki/Special:Contributions/' + encodeURIComponent(creator)).text(editCount + ' edits').css({'color': '#0645ad'})) |
.append($('<a>').attr('href', wikiURL + '/wiki/Special:Contributions/' + encodeURIComponent(creator)).text(editCount + ' edits').css({'color': '#0645ad'})) |
||
.append(')') |
.append(')') |
||
.css({'font-size': ' |
.css({'font-size': '84%', 'color': '#666', 'margin-top': '5px'}); |
||
$('#bodyContent').prepend(creatorInfo); |
$('#bodyContent').prepend(creatorInfo); |
Revision as of 10:08, 26 December 2023
$(document).ready(function() {
// Only execute in view mode
if (mw.config.get('wgAction') === "view") {
var apiURL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php';
var wikiURL = mw.config.get('wgServer') + mw.config.get('wgScriptPath');
// Fetches the creator of the current page
function fetchPageCreator() {
$.ajax({
url: apiURL,
data: {
action: 'query',
format: 'json',
titles: mw.config.get('wgPageName'),
prop: 'revisions',
rvlimit: 1,
rvdir: 'newer',
rvprop: 'user'
},
dataType: 'json',
success: function(response) {
var pageId = Object.keys(response.query.pages)[0];
fetchUserEditCount(response.query.pages[pageId].revisions[0].user);
}
});
}
// Fetches the edit count of the creator
function fetchUserEditCount(username) {
$.ajax({
url: apiURL,
data: {
action: 'query',
format: 'json',
list: 'users',
ususers: username,
usprop: 'editcount'
},
dataType: 'json',
success: function(response) {
displayCreator(username, response.query.users[0].editcount);
}
});
}
// Displays creator info below the title bar
function displayCreator(creator, editCount) {
var creatorInfo = $('<div>')
.append('Page created by: ')
.append($('<a>').attr('href', wikiURL + '/wiki/User:' + encodeURIComponent(creator)).text(creator).css({'color': '#0645ad'}))
.append(' (')
.append($('<a>').attr('href', wikiURL + '/wiki/Special:Contributions/' + encodeURIComponent(creator)).text(editCount + ' edits').css({'color': '#0645ad'}))
.append(')')
.css({'font-size': '84%', 'color': '#666', 'margin-top': '5px'});
$('#bodyContent').prepend(creatorInfo);
}
fetchPageCreator();
}
});