脆的千喜問題

刪除Threads的互動統計數據中超過1K時會出現的".0",其應是整數而非浮點數。

目前為 2024-05-25 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         脆的千喜問題
// @name:ja      ThreadsS1K問題
// @name:en     ThreadsS1KProblem
// @description  刪除Threads的互動統計數據中超過1K時會出現的".0",其應是整數而非浮點數。
// @namespace    https://github.com/Max46656
// @version      1.1
// @author       Max
// @description:ja Threads のインタラクション統計データで、1K を超える場合に表示される「.0」を削除し、整數にする必要があります。
// @description:en Delete ".0" in Threads interact stat when it's over 1K, which should be an integer instead of a float.
// @match        https://www.threads.net/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=threads.net
// @grant        none
// @license MPL2.0
// ==/UserScript==


class InteractStatChanger {
    constructor() {
        this.interactStatObserver = new MutationObserver(this.handleNewPosts.bind(this));
        //空格以搜尋符合條件的父元素下符合條件的子元素
        this.interactStatClassName='.x6ikm8r.x10wlt62 .x1lliihq.x1plvlek.xryxfnj.x1n2onr6.x193iq5w.xeuugli.x1fj9vlw.x13faqbe.x1vvkbs.x1s928wv.xhkezso.x1gmr53x.x1cpjm7i.x1fgarty.x1943h6x.x1i0vuye.xmd891q.xo1l8bm.xc82ewx.x1yc453h';
    }

    startObserving() {
        this.interactStatObserver.observe(document.body, { subtree: true, childList: true,attributes: true});
    }

    stopObserving() {
        this.interactStatObserver.disconnect();
    }

    handleNewPosts(mutationsList) {
        const interactStatElements = document.querySelectorAll(this.interactStatClassName);
        interactStatElements.forEach(element => {
            Array.from(element.childNodes).forEach(node => {
                node.nodeValue=this.toInteger(node);
            });
        });
    }

    toInteger(node){
        if (node.nodeType !== Node.TEXT_NODE || !node.nodeValue.match(/\.0/g)) {
            return node.nodeValue
        }else {
            console.log('L1KProblemFound');
            return node.nodeValue.replace(/\.0/g, '');
        }
    }

}


const johnTheMathTeacher = new InteractStatChanger();
johnTheMathTeacher.startObserving();