pawoo.net 顯示轉嘟與最愛

把隱藏的轉嘟與最愛顯示出來

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

// ==UserScript==
// @name         pawoo.net 顯示轉嘟與最愛
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @description  把隱藏的轉嘟與最愛顯示出來
// @author       BeenYan
// @match        https://pawoo.net/web/timelines/home
// @icon         https://www.google.com/s2/favicons?sz=64&domain=pawoo.net
// @license MIT
// @run-at       document-start
// @grant        GM_addElement
// ==/UserScript==

/**
 *  DATA struct {
 *      id: string, // 搜索文章識別符號
 *      favourites_count: number, // 最愛人數
 *      reblogs_count: number, // 轉嘟人數
 *  }
 */

const delay = ms => new Promise(res => setTimeout(res, ms));

function number_dom(parent, num) {
    parent.classList.add('icon-button--with-counter');
    GM_addElement(parent, 'span', {
        class: 'icon-button__counter',
        textContent: num
    });
}

async function get_action_bar(id) {
    const ACTION_BAR = document.querySelectorAll(`[data-id="${id}"] .status__action-bar-button`);
    if (ACTION_BAR.length === 0) {
        await delay(1000);
        return get_action_bar(id);
    }

    return ACTION_BAR;
}

async function render(dataList) {
    /**
     * 0 => 回覆
     * 1 => 轉嘟
     * 2 => 最愛
     */
    for (const data of dataList) {
        const ACTION_BAR = await get_action_bar(data.id); 
        console.log(ACTION_BAR[0]);
        number_dom(ACTION_BAR[1], data.reblogs_count);
        number_dom(ACTION_BAR[2], data.favourites_count);
    }
}

(function(open) {
    unsafeWindow.XMLHttpRequest.prototype.open = function() {
        this.addEventListener('load', function() {
            if (this.responseURL.startsWith('https://pawoo.net/api/v1/timelines/') !== true) {
                return;
            }

            const DATA_LIST = JSON.parse(this.response);
            render(DATA_LIST);
        }, false);
        open.apply(this, arguments);
    };
})(unsafeWindow.XMLHttpRequest.prototype.open);

window.addEventListener('keydown', (event) => {
    const KEY = event.key;
    if (KEY !== "F5") {
        return;
    }

    location.reload(true);
    event.preventDefault();
})

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址