Greasy Fork

Greasy Fork is available in English.

掘金文章详情页,添加文章等级注释

try to take over the world!

目前为 2021-12-19 提交的版本。查看 最新版本

// ==UserScript==
// @name         掘金文章详情页,添加文章等级注释
// @namespace    http://tampermonkey.net/
// @version      0.8
// @description  try to take over the world!
// @author       You
// @include     https://juejin.cn/post/*
// @grant        none
// ==/UserScript==

(function () {
    "use strict";

    setTimeout(() => {
        let viewData = document.querySelector(".views-count").innerText.replace(/阅读|\s|·/g, "");
        let likeData = document.querySelector(".like-btn").getAttribute("badge");
        if (likeData < 50) {
            return;
        }
        let level = Math.round((likeData * 100) / viewData);
        var newNode = document.createElement("div");
        newNode.setAttribute("class", "panel-btn like-adjust");
        newNode.innerText = level;
        newNode.style.color = "#ffffff";
        newNode.style.backgroundColor = `rgba(0, 127, 255, ${level / 10})`;
        newNode.style.lineHeight = "48px";
        newNode.style.textAlign = "center";
        newNode.style.fontWeight = "bold";
        newNode.style.borderRadius = "50%";
        newNode.style.marginBottom = ".75rem";
        newNode.style.fontSize = "18px";
        let node = document.querySelector(".article-suspended-panel");
        node.insertBefore(newNode, node.childNodes[0]);

        let theClientHeight = document.body.clientHeight;
        var newNode1 = document.createElement("div");
        newNode1.setAttribute("class", "panel-btn like-adjust");
        newNode1.innerText = theClientHeight;
        newNode1.style.color = "#ffffff";
        newNode1.style.backgroundColor = `rgba(0, 127, 255, ${level / 10})`;
        newNode1.style.lineHeight = "48px";
        newNode1.style.textAlign = "center";
        newNode1.style.borderRadius = "50%";
        newNode1.style.marginBottom = ".75rem";
        newNode1.style.fontSize = "12px";
        node.insertBefore(newNode1, node.childNodes[0]);
    }, 2000);
})();