Auto Expand Usage (Gear Browser Compatible)

Auto-expand all "View", "Details", "More", <details>, and aria-expanded items on usage pages.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Auto Expand Usage (Gear Browser Compatible)
// @namespace      http://tampermonkey.net/
// @version        2.0
// @description    Auto-expand all "View", "Details", "More", <details>, and aria-expanded items on usage pages.
// @match          *://*.koodomobile.com/*
// @match          *://*.telus.com/*
// @run-at         document-end
// @grant          none
// ==/UserScript==

(function() {

    function clickButtons() {
        const keywords = ["view", "details", "show", "expand", "more", "usage", "see", "open"];
        let count = 0;

        document.querySelectorAll("button, a, div[role='button'], span").forEach(el => {
            const text = (el.innerText || "").toLowerCase().trim();
            if (!text) return;

            for (let k of keywords) {
                if (text.includes(k)) {
                    try {
                        el.click();
                        count++;
                    } catch (e) {}
                    break;
                }
            }
        });

        return count;
    }

    function openDetails() {
        let opened = 0;
        document.querySelectorAll("details").forEach(d => {
            if (!d.open) {
                d.open = true;
                opened++;
            }
        });
        return opened;
    }

    function expandAria() {
        let expanded = 0;
        document.querySelectorAll("[aria-expanded='false']").forEach(el => {
            try {
                el.click();
                expanded++;
            } catch (e) {}
        });
        return expanded;
    }

    function scrollPage() {
        window.scrollBy(0, 9999);
    }

    function expandLoop() {
        let idle = 0;

        const interval = setInterval(() => {
            const a = clickButtons();
            const b = openDetails();
            const c = expandAria();

            scrollPage();

            if (a + b + c === 0) {
                idle++;
            } else {
                idle = 0;
            }

            if (idle >= 5) {
                clearInterval(interval);
            }
        }, 900);
    }

    // Start after slight delay
    setTimeout(expandLoop, 1500);

})();