Jump to content

User:Kevin SF/category-stats.js

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Kevin SF (talk | contribs) at 15:09, 7 May 2022 (Initial test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* jshint esversion: 8, esnext: false */

// Show link to the "Massviews Analysis" on category pages
if (mw.config.get("wgCanonicalNamespace") === "Category" && mw.config.get("wgAction") === "view")
{
    Promise.all([
        mw.loader.using('mediawiki.util'),
        new Promise((resolve) => {
            if (document.readyState === "loading")
            {
                return resolve();
            }
            window.addEventListener("load", () => resolve());
            document.addEventListener("DOMContentLoaded", () => resolve());
        })
    ]).then(() => {
        let baseMassviewLink = "https://pageviews.wmcloud.org/massviews/?platform=all-access&agent=user&source=category&range=latest-20&subjectpage=0&subcategories=1";
        
        mw.util.addPortletLink(
            'p-cactions', // portletId
            baseMassviewLink.concat(`&target=${location.href}`), // href
            'Category Stats', // Text
            'ca-category-page-statistics', // element id
            'Shows pages in this category with statistics, such as view counts', // Tooltip text
            null, // keyboard shortcut key
            // 'nextnode' // Element to be added in front of
        );
    });
}