User:Dionysius Miller/UserContributions.js

// Load OOUI library explicitly mw.loader.load('oojs-ui-core');

// Wait for the library to load mw.loader.using('oojs-ui-core').done(function {    // Code to run after OOUI is loaded    console.log('OOUI library loaded');

// Your existing code here...

// Fetch and process data from API var api = new mw.Api; api.get({       action: 'query',        format: 'json',        list: 'categorymembers',        cmtitle: 'Category:' + category,        cmlimit: 'max'    }).done(function (data) {        console.log('Category Members Data:', data);

var userContributions = {};

// Process each page in the category data.query.categorymembers.forEach(function (page) {           var pageTitle = page.title;

console.log('Processing Page:', pageTitle);

// Fetch revision history for the page api.get({               action: 'query',                format: 'json',                titles: pageTitle,                prop: 'revisions',                rvlimit: 'max',                rvprop: 'size|user'            }).done(function (revisionData) {                console.log('Revision Data for Page:', pageTitle, revisionData);

// Process revisions for the page Object.values(revisionData.query.pages).forEach(function (pageInfo) {                   var pageRevisions = pageInfo.revisions || [];

// Calculate contributions for each user userList.forEach(function (user) {                       userContributions[user] = userContributions[user] || { added_bytes: 0, removed_bytes: 0 };

pageRevisions.forEach(function (revision) {                           if (revision.user === user) {                                userContributions[user].added_bytes += revision.size;                            }                        }); });               });

console.log('User Contributions:', userContributions);

// Display the output on the page var output = '{| class="wikitable"\n|-\n! Rank !! Total Bytes !! User\n'; var sortedUsers = Object.keys(userContributions).sort(function (a, b) {                   return userContributions[b].added_bytes - userContributions[a].added_bytes;                });

sortedUsers.forEach(function (user, index) {                   var totalBytes = userContributions[user].added_bytes;

// Apply colors based on counts var color; if (index < parseInt(mw.util.getParamValue('count1') || 0)) { color = mw.util.getParamValue('color1') || 'green'; } else if (index < parseInt(mw.util.getParamValue('count2') || 0)) { color = mw.util.getParamValue('color2') || 'yellow'; } else if (index < parseInt(mw.util.getParamValue('count3') || 0)) { color = mw.util.getParamValue('color3') || 'orange'; } else if (index < parseInt(mw.util.getParamValue('count4') || 0)) { color = mw.util.getParamValue('color4') || 'red'; } else if (index < parseInt(mw.util.getParamValue('count5') || 0)) { color = mw.util.getParamValue('color5') || 'purple'; } else { color = 'white'; }

output += '|-\n| ' + (index + 1) + ' || style="background-color:' + color + ';" | ' + totalBytes + ' || ' + user + '\n'; });

output += '|}';

// Display the output on the page $('#topicContributionsTable').html(output); });       });    }); });