显示米哈云游排队详情

显示米哈云游排队人数和更精确的时间

// ==UserScript==
// @name         显示米哈云游排队详情
// @namespace    https://rebuild.moe/
// @homepage     https://gist.github.com/Shimogawa/c9451df3e32cc4df77dfe1f080c7a327
// @version      2024.2.7
// @description  显示米哈云游排队人数和更精确的时间
// @author       Rebuild
// @license      MIT
// @match        https://ys.mihoyo.com/cloud/*
// @match        https://sr.mihoyo.com/cloud/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mihoyo.com
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const queryApiPath = '/api/getDispatchTicketInfo';

    const getWaitingWindow = () => {
        return document.querySelector(".waiting-wrapper");
    };

    const originalSend = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.send = function () {
        const self = this;
        this.onreadystatechange = function () {
            if (self.readyState === 4 && self.responseURL.endsWith(queryApiPath)) {
                const waitingWindow = getWaitingWindow();
                if (!waitingWindow) {
                    return;
                }
                const minuteShow = waitingWindow.querySelector(".single-row__val");
                if (!minuteShow) {
                    return;
                }
                const resp = JSON.parse(self.response);
                if (!resp || resp.retcode !== 0) {
                    return;
                }
                const data = resp.data;
                if (data.ticket_status !== 'QUEUEING') {
                    return;
                }
                minuteShow.innerHTML = `<span>${data.queue_info.waiting_time_min}</span> <span class="slash-deep-color">分钟,当前在</span> `
                    + `<span>${data.queue_info.queue_rank}/${data.queue_info.branch_queue_len}</span> <span class="slash-deep-color">位</span>`;
            }
        }
        originalSend.apply(this, arguments);
    }
})();