Blutopia actual buffer

Shows your actual buffer(to 1.0 ratio) next to blutopias buffer(0.4 ratio)

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Blutopia actual buffer
// @description  Shows your actual buffer(to 1.0 ratio) next to blutopias buffer(0.4 ratio)
// @match        http://blutopia.xyz/*
// @match        https://blutopia.xyz/*
// @exclude      /https?:\/\/blutopia\.xyz\/login/
// @exclude      /https?:\/\/blutopia\.xyz\/register/
// @exclude      /https?:\/\/blutopia\.xyz\/password\/reset/
// @exclude      /https?:\/\/blutopia\.xyz\/username\/reminder/
// @exclude      /https?:\/\/blutopia\.xyz\/application/
// @exclude      /https?:\/\/blutopia\.xyz\/rss\/.*/
// @version 0.0.1.20200714150437
// @namespace https://greasyfork.org/users/656892
// ==/UserScript==
try {
    var fileSize = /(\d+\.\d+) (([PTG]i)?B)/;
    var li = document.getElementById("main-content").getElementsByClassName("list-inline")[0].getElementsByTagName("li");
    var upload = toGiB(trimHTML(li[2].innerHTML));
    var download = toGiB(trimHTML(li[3].innerHTML));

    li[5].innerHTML = li[5].innerHTML.replace("iB", "iB / " + GiBtoString((upload - download)));
} catch(err) { /*prob on a page without the header thing*/ }

function trimHTML(string) {
    return string.replace(/(<([^>]+)>)|\n|/,"").replace(/ {2,}/, " ").trim();
}

function toGiB(string) {
    var regexp = string.match(fileSize);
    if(regexp == null) {
        return 0;
    }
    var size = parseFloat(regexp[1]);
    var unit = regexp[2];
    var factor;
    switch(unit) {
        case "PiB":
            factor = 1024*1024;
            break;
        case "TiB":
            factor = 1024;
            break;
        case "GiB":
            factor = 1;
            break;
        default:
            return 0;
    }
    return size * factor;
}

function GiBtoString(GiB) {
    var TiB = 1024;
    var PiB = TiB*TiB;
    var unit = " GiB";
    var size = GiB;

    if(GiB >= TiB && GiB < PiB) {
        unit = " TiB";
        size = GiB/TiB;
    } else if(GiB >= PiB) {
        unit = " PiB";
        size = GiB/PiB;
    }

    return size.toFixed(2) + unit;
}