AvistaZ H&R stats

Shows you if a torrent is H&R before you stop seeding it

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AvistaZ H&R stats
// @description  Shows you if a torrent is H&R before you stop seeding it
// @require      http://code.jquery.com/jquery-3.5.1.js
// @match        http://avistaz.to/profile/*/history*
// @match        https://avistaz.to/profile/*/history*
// @version 0.0.1.20200627153427
// @namespace https://greasyfork.org/users/656892
// ==/UserScript==

var tbl = document.getElementsByTagName('tbody')[0];

var span = document.createElement("span");
span.appendChild(document.createTextNode("H&R?"));
var th = document.createElement("th");
th.appendChild(span);
document.getElementsByTagName('thead')[0].rows[0].appendChild(th);

var fileSize = /(\d+\.\d+) ([TGMK]?B)/;

function appendColumn() {
    for (var i = 0; i < tbl.rows.length; i++) {
        var row = tbl.rows[i];

        var size = toGB(row.cells[1].innerHTML.match(fileSize)[0]);
        var downloaded = toGB(row.cells[6].innerHTML.match(fileSize)[0]);
        var ratio = row.cells[7].innerHTML.match(/(\d+\.\d+)|∞/)[0];
        ratio == "∞" ? 999.99 : parseFloat(ratio);

        var seedTimeHrs = parseInt(row.cells[10].innerHTML.match(/\d+/)[0])/60;

        var hoursLeft = hoursNeeded(size) - seedTimeHrs;
        var isHnR = ratio < 0.9 && downloaded/size >= 0.1 && hoursLeft > 0;

        createCell(row.insertCell(-1), isHnR? hoursLeft.toFixed(2) : 0, (isHnR ? "text-red" : "text-success") + " text-bold");
    }
}

function hoursNeeded(size) {
    return size < 50 ?
        72 + (2*size) :
        (100*Math.log(size))-219.2023;
}

function toGB(string) {
    var regexp = string.match(fileSize);
    var size = parseFloat(regexp[1]);
    var unit = regexp[2];
    var factor;
    switch(unit) {
        case "TB":
            factor = 1000;
            break;
        case "GB":
            factor = 1;
            break;
        case "MB":
            factor = 1/1000;
            break;
        case "KB":
            factor = 1/1000000; // 10^-6
            break;
        case "B":
            factor = 1/1000000000; // 10^-9
            break;
        default:
            return 0;
    }
    return size * factor;
}

function createCell(cell, text, style) {
    var div = document.createElement('span'),
        txt = document.createTextNode(text);
    div.appendChild(txt);
    div.setAttribute('class', style);
    cell.appendChild(div);
}

appendColumn();