Greasy Fork

Greasy Fork is available in English.

掘金文章等级标注

在掘金文章的详情页,标注当前文章等级,Lv3 以下文章不建议阅读。

目前为 2023-03-23 提交的版本。查看 最新版本

// ==UserScript==
// @name         掘金文章等级标注
// @namespace    http://tampermonkey.net/
// @version      0.9
// @description  在掘金文章的详情页,标注当前文章等级,Lv3 以下文章不建议阅读。
// @author       You
// @include     https://juejin.cn/post/*
// @grant        none
// ==/UserScript==

(function () {
    "use strict";

    setTimeout(() => {
        const viewData = document.querySelector(".views-count").innerText.replace(/阅读|\s|·/g, "");
        const panelBtns = document.querySelectorAll(".with-badge");
        const likeData = panelBtns[0].getAttribute("badge");
        const collectData = panelBtns[2].getAttribute("badge");
        const score = likeData * 0.25 + collectData * 0.75;
        if (score < 50 || viewData < 1000) {
            return;
        }
        const level = Math.round((score * 100) / viewData);

        const buttonNode = document.createElement("div");
        buttonNode.innerText = `Lv ${level}`;
        buttonNode.style.marginBottom = "1.667rem";
        buttonNode.style.width = "4rem";
        buttonNode.style.height = "4rem";
        buttonNode.style.backgroundColor = `rgba(0, 127, 255, ${(level || 0.5) * 0.2})`;
        buttonNode.style.borderRadius = "50%";
        buttonNode.style.textAlign = "center";
        buttonNode.style.fontSize = "1.4rem";
        buttonNode.style.color = "#ffffff";
        buttonNode.style.fontWeight = "bold";
        buttonNode.style.lineHeight = "4rem";
        const panelNode = document.querySelector(".article-suspended-panel");
        panelNode.insertBefore(buttonNode, panelNode.childNodes[0]);
    }, 2000);
})();