刪除Threads的互動統計數據中超過1K時會出現的".0",其應是整數而非浮點數。
当前为
// ==UserScript==
// @name 脆的千喜問題
// @name:ja ThreadsS1K問題
// @name:en ThreadsS1KProblem
// @description 刪除Threads的互動統計數據中超過1K時會出現的".0",其應是整數而非浮點數。
// @namespace https://github.com/Max46656
// @version 1.2
// @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.handleAllPosts.bind(this));
// 空格以搜尋符合條件的父元素下符合條件的子元素,將class中的空格以"."取代
this.interactStatClassName='div.x6ikm8r.x10wlt62 span.x1lliihq.x1plvlek.xryxfnj.x1n2onr6.x193iq5w.xeuugli.x1fj9vlw.x13faqbe.x1vvkbs.x1s928wv.xhkezso.x1gmr53x.x1cpjm7i.x1fgarty.x1943h6x.x1i0vuye.xmd891q.xo1l8bm';
}
startObserving() {
this.interactStatObserver.observe(document.body, { subtree: true, childList: false, characterData: true });
}
stopObserving() {
this.interactStatObserver.disconnect();
}
handleAllPosts() {
this.stopObserving();
const interactStatElements = document.querySelectorAll(this.interactStatClassName);
console.log('interactStat有', interactStatElements.length, '個 at ', new Date().toLocaleString());
interactStatElements.forEach(element => {
Array.from(element.childNodes).forEach(node => {
node.nodeValue = this.toInteger(node);
});
});
this.startObserving();
}
toInteger(node) {
if (node.nodeType !== Node.TEXT_NODE || !node.nodeValue.match(/\.0/g)) {
return node.nodeValue;
} else {
console.log('L1KProblemFound ', node.nodeValue);
return node.nodeValue.replace(/\.0/, '');
}
}
}
const johnTheMathTeacher = new InteractStatChanger();
johnTheMathTeacher.startObserving();
window.onload = (event) => {
johnTheMathTeacher.handleAllPosts();
};
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址