BUFF自动计算当前商品倒余额的利率

自动在商品界面的价格旁添加一个利率标签

目前为 2024-05-04 提交的版本。查看 最新版本

// ==UserScript==
// @name         BUFF自动计算当前商品倒余额的利率
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  自动在商品界面的价格旁添加一个利率标签
// @author       You
// @match        https://buff.163.com/goods/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=163.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';
    window.onload = function () {//等待页面加载完成,否则抛出错误
        let regexPrice = /\d+\.\d+/;//匹配第一个浮点数
        let PriceDOM;
        setTimeout(main, 200);
        function main() {
            PriceDOM = document.getElementsByClassName("f_Strong");
            if (PriceDOM) {
                if (PriceDOM.length < 2) {
                    setTimeout(main, 200);
                    return;
                }
                console.log(PriceDOM);
                let steamPriceText = PriceDOM[1].innerText;
                let steamPrice = (regexPrice.exec(steamPriceText)[0]);
                let buffslowestPriceText = PriceDOM[2].innerText;
                let buffslowestPrice = (regexPrice.exec(buffslowestPriceText))[0];
                let RateLabel = document.createElement("label"); //创建一个标签
                let Rate = calculateInterestRates(steamPrice, buffslowestPrice);
                console.log(Rate);
                RateLabel.innerHTML = "利率" + Rate + "%";
                PriceDOM[1].appendChild(RateLabel);
                function calculateInterestRates(steamPrice, buffslowestPrice) {
                    let InterestRates = (steamPrice * 0.9 - buffslowestPrice) / buffslowestPrice;
                    InterestRates = Math.round(InterestRates * 10000) / 100;//保留四位小数,并且变成百分数,需要加%
                    return InterestRates;
                };
            }
        }
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址