Greasy Fork is available in English.

Append Rank by WatchNumber/LikeNumber in the Suno.ai Single Page

Find similar elements and append their rank by watch number in descending order.

// ==UserScript==
// @name         Append Rank by WatchNumber/LikeNumber in the Suno.ai Single Page
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @description  Find similar elements and append their rank by watch number in descending order.
// @author       aspen138
// @match        *://app.suno.ai/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=suno.ai
// @grant        none
// @license      MIT
// ==/UserScript==





(function() {
    'use strict';

    // Function to append rankings based on text content numbers
    function appendRankings(selector) {
        window.addEventListener('load', function() {
            // Find elements matching the selector and convert NodeList to Array
            const elements = Array.from(document.querySelectorAll(selector));

            console.log("elements=", elements);

            // Filter, sort, and append rank in a combined step
            elements
                .filter(el => el.querySelector('p')) // Filter elements containing a <p> tag
                .sort((a, b) => { // Sort elements by the number inside <p> in descending order
                    const aNumber = parseInt(a.querySelector('p').textContent, 10);
                    const bNumber = parseInt(b.querySelector('p').textContent, 10);
                    return bNumber - aNumber;
                })
                .forEach((element, index) => { // Append a rank span to each element
                    const rankDisplay = document.createElement('span');
                    rankDisplay.style.marginLeft = '10px';
                    rankDisplay.textContent = `Rank${index + 1}'`;
                    rankDisplay.className="chakra-text css-19h91tu";
                    element.appendChild(rankDisplay);
                });

            console.log("sortedElements", elements); // Debugging
        });
    }

    // Call the function for both selectors
    appendRankings('button[data-theme="dark"][aria-label="Play Count"].css-1v0yma7');
    appendRankings('button[data-theme="dark"][aria-label="like-button"]');
})();