User:Euphoria/common.js

From Test Wiki
Revision as of 07:53, 14 November 2023 by Euphoria (talk | contribs) (edit count)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// 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>');