User:Euphoria/common.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
No edit summary
(edit count)
Line 1: Line 1:
mw.loader.using(['mediawiki.util']).then(function () {
// Function to get edit count and display it
     var pageTitle = mw.config.get('wgTitle');
function getEditCount() {
    var username = pageTitle.split('/')[mw.config.get('wgNamespaceNumber') === 2 || mw.config.get('wgNamespaceNumber') === 3 ? 0 : 1];
     const apiUrl = 'https://testwiki.wiki/w/api.php?action=query&format=json&list=users&usprop=editcount&ususers=' + mw.config.get('wgTitle');


     if (mw.config.get('wgNamespaceNumber') === 2 || mw.config.get('wgNamespaceNumber') === 3 || mw.config.get('wgCanonicalSpecialPageName') === 'Contributions') {
     fetch(apiUrl)
         var sulLink = mw.util.addPortletLink(
        .then(response => response.json())
             'p-cactions',
        .then(data => {
             mw.util.getUrl('Special:CentralAuth/' + username),
            const editCount = data.query.users[0].editcount;
            'SUL',
            $('#editCountResult').text('Edit count: ' + editCount);
            'ca-sul',
        })
            'SUL',
         .catch(error => {
            null,
             console.error('Error fetching data:', error);
            '#ca-sul'
             $('#editCountResult').text('Error fetching edit count.');
        );
        });
    }
}
});
 
// Add a button to trigger the edit count retrieval
$('#firstHeading').append('<button onclick="getEditCount()">Get Edit Count</button>');
 
// Add a placeholder for displaying the edit count
$('#firstHeading').append('<p id="editCountResult"></p>');

Revision as of 07:53, 14 November 2023

// Function to get edit count and display it
function getEditCount() {
    const apiUrl = 'https://testwiki.wiki/w/api.php?action=query&format=json&list=users&usprop=editcount&ususers=' + mw.config.get('wgTitle');

    fetch(apiUrl)
        .then(response => response.json())
        .then(data => {
            const editCount = data.query.users[0].editcount;
            $('#editCountResult').text('Edit count: ' + editCount);
        })
        .catch(error => {
            console.error('Error fetching data:', error);
            $('#editCountResult').text('Error fetching edit count.');
        });
}

// Add a button to trigger the edit count retrieval
$('#firstHeading').append('<button onclick="getEditCount()">Get Edit Count</button>');

// Add a placeholder for displaying the edit count
$('#firstHeading').append('<p id="editCountResult"></p>');