[GC] UL Trophy ordering

Order trophies by gold/silver/bronze in every userlookup!

目前為 2023-12-08 提交的版本,檢視 最新版本

// ==UserScript==
// @name         [GC] UL Trophy ordering
// @version      1.0
// @description  Order trophies by gold/silver/bronze in every userlookup!
// @author       You
// @match        https://www.grundos.cafe/userlookup/?user=giovanna
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @license      MIT
// @namespace https://greasyfork.org/users/1230396
// ==/UserScript==

// Wrap the script in a function to avoid polluting the global scope
function setOrderAsCssProperty() {
    // Select all elements with class "ul__gametrophy"
    var elements = document.querySelectorAll('.ul__gametrophy');

    // Iterate through each element
    elements.forEach(function (element) {
        // Find the img element
        var imgElement = element.querySelector('img');

        // If img element is found
        if (imgElement) {
            // Extract the src attribute
            var srcAttribute = imgElement.getAttribute('src');

            // Extract the URL end
            var urlEnd = srcAttribute.substring(srcAttribute.lastIndexOf('/') + 1);

            // Extract the order from the URL end
            var orderMatch = urlEnd.match(/_(\d+)\.gif/);
            var order = orderMatch ? orderMatch[1] : '';

            // Set the order as a CSS property for the element
            element.style.order = order;
        }
    });
}

// Call the function
setOrderAsCssProperty();