Zhihu-K

知乎赞同数用K显示

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Zhihu-K
// @namespace    https://gist.github.com/rain15z3/82f8d7a5d4778d969d92211c9dfe2fed
// @version      1.0
// @description  知乎赞同数用K显示
// @author       RainbowBird
// @match        https://www.zhihu.com/*
// @grant        none
// @require      http://code.jquery.com/jquery-1.11.0.min.js
// ==/UserScript==

!(function () {
    setInterval(refrush, 3000);
})();

function refrush() {
    console.log("[Zhihu-K] loading...");
    $(".Button.VoteButton.VoteButton--up").each(function () {
        var text = $(this).contents().eq(1).get(0).nodeValue;

        text = text.replace(/\u200B/g, "");
        var rep = text.replace("赞同 ", "");
        if (text.match("万")) {
            rep = rep.replace(" 万", "");
            var num = parseFloat(rep) * 10000;
        } else {
            var num = parseFloat(rep);
        }

        if (num >= 10000 || (num >= 1000 && num < 10000)) {
            var numk = num / 1000;
            if (numk.toString().match(".")) numk = numk.toFixed(1);
            text = "赞同 " + numk + " K";
        }

        $(this).contents().eq(1).get(0).nodeValue = text;
    });
}