RosettaCode Conribution Records Counter

count specific li elements within section.mw-pager-body

Από την 12/02/2024. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         RosettaCode Conribution Records Counter
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  count specific li elements within section.mw-pager-body
// @author       aspen138
// @match        *://rosettacode.org/wiki/Special:Contributions?end=&limit=5000&namespace=all&start=&tagfilter=&target=*
// @match        *://rosettacode.org/wiki/Special:Contributions*
// @grant        none
// @license    MIT
// ==/UserScript==

(function() {
    'use strict';

     function countAndDisplayLiElements() {
        // Find the target section
        var section = document.querySelector('section.mw-pager-body');
        if (!section) return;

        // Count li elements that match the first criteria
        var liElementsFirstCriteria = section.querySelectorAll('li.mw-contributions-current.mw-tag-wikieditor');
        var countFirstCriteria = liElementsFirstCriteria.length;

        // Count li elements that match the second criteria
        var liElementsSecondCriteria = section.querySelectorAll('li.mw-tag-wikieditor');
        var countSecondCriteria = liElementsSecondCriteria.length;

        // Create a new element to display the count for the first criteria
        var resultDisplayFirstCriteria = document.createElement('div');
        resultDisplayFirstCriteria.textContent = `Count of li elements with "mw-contributions-current.mw-tag-wikieditor": ${countFirstCriteria}`;
        resultDisplayFirstCriteria.style.backgroundColor = 'yellow'; // Set the background color to blue
        resultDisplayFirstCriteria.style.color = 'blue'; // Optional: Set text color to white for better readability
        resultDisplayFirstCriteria.style.padding = '10px'; // Optional: Add some padding
        resultDisplayFirstCriteria.style.marginBottom = '10px'; // Optional: Add some margin at the bottom
        resultDisplayFirstCriteria.style.border = "2px solid black";

        // Create a new element to display the count for the second criteria
        var resultDisplaySecondCriteria = document.createElement('div');
        resultDisplaySecondCriteria.textContent = `(RosettaCode Conribution Records Counter) Count of li elements with "mw-tag-wikieditor": ${countSecondCriteria}`;
        resultDisplaySecondCriteria.style.backgroundColor = 'yellow'; // Set the background color to blue
        resultDisplaySecondCriteria.style.color = 'blue'; // Optional: Set text color to white for better readability
        resultDisplaySecondCriteria.style.padding = '10px'; // Optional: Add some padding
        resultDisplaySecondCriteria.style.marginBottom = '10px'; // Optional: Add some margin at the bottom
        resultDisplaySecondCriteria.style.border = "2px solid black";

        // Insert the results as the first children of the section
        if (section.firstChild) {
            section.insertBefore(resultDisplaySecondCriteria, section.firstChild);
            section.insertBefore(resultDisplayFirstCriteria, resultDisplaySecondCriteria);
        } else {
            section.appendChild(resultDisplayFirstCriteria);
            section.appendChild(resultDisplaySecondCriteria);
        }
    }

    // Assuming this function is called when the document is fully loaded
    window.addEventListener('load', countAndDisplayLiElements);
})();