Add TD to Points Row

Add a td into the Points row in the provided HTML table

// ==UserScript==
// @name         Add TD to Points Row
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Add a td into the Points row in the provided HTML table
// @author       Your Name
// @match        https://pt.keepfrds.com/torrents.php*
// @grant        none
// @license MIT 
// ==/UserScript==

(function() {
    'use strict';

    function sizeStringToGB(sizeString) {
        var sizeRegex = /(\d+(\.\d+)?)(\s*)(GB|MB|TB)/i;
        var matches = sizeRegex.exec(sizeString.trim());
        if (!matches) return 0;
        var value = parseFloat(matches[1]);
        var unit = matches[4].toLowerCase();
        switch (unit) {
            case 'gb':
                return value.toFixed(5);
            case 'mb':
                return (value / 1024).toFixed(5);
            case 'tb':
                return (value * 1024).toFixed(5);
            default:
                return 0;
        }
    }

    function timeStringToWeeks(timeString) {
        var hoursRegex = /(\d+)\s*时/;
        var daysRegex = /(\d+)\s*天/;
        var monthsRegex = /(\d+)\s*月/;
        var yearsRegex = /(\d+)\s*年/;
        var totalMinutes = 0;
        [hoursRegex, daysRegex, monthsRegex, yearsRegex].forEach(regex => {
            var match = regex.exec(timeString);
            if (match) {
                var value = parseInt(match[1]);
                if (regex === hoursRegex) totalMinutes += value * 60;
                else if (regex === daysRegex) totalMinutes += value * 1440;
                else if (regex === monthsRegex) totalMinutes += value * 43200;
                else if (regex === yearsRegex) totalMinutes += value * 525600;
            }
        });
        var weeks = totalMinutes / 10080;
        return weeks.toFixed(10);
    }

    var magicValueHeader = '<td class="colhead">A值</td>';
    var magicValueHeader2 = '<td class="colhead">A值每GB</td>';
    var magicValueHeader3 = '<td class="colhead">官方预期</td>';
    var torrentsTable = document.querySelector('table.torrents');
    if (torrentsTable) {
        var columnCounter = 0;
        var colheadCells = torrentsTable.querySelectorAll('td.colhead');
        colheadCells.forEach(function(cell) {
            columnCounter++;
            if (columnCounter === 9) {
                cell.insertAdjacentHTML('afterend', magicValueHeader3);
                cell.insertAdjacentHTML('afterend', magicValueHeader2);
                cell.insertAdjacentHTML('afterend', magicValueHeader);
            }
        });
    }

    var dataRows = document.querySelectorAll('table.torrents tr:not(:first-child)');
    dataRows.forEach(function(row) {
        var textCell = row.querySelector('td:nth-child(2)');

        var extractedNumber = '';
        var spanElement = textCell.querySelector('span');
        //console.log(spanElement);

        // Extract the text content of the span, which should be the number, removing any surrounding HTML tags
        extractedNumber = spanElement.textContent.trim();


        var timeCell = row.querySelector('td:nth-child(4)');
        var sizeCell = row.querySelector('td:nth-child(5)');
        var seederCell = row.querySelector('td:nth-child(6)');
        var timeString = timeCell.innerText;
        var sizeString = sizeCell.innerText;
        var numOfSeeders = parseInt(seederCell.innerText.replace(/,/g, ''));
        var weeks = timeStringToWeeks(timeString);
        var size = sizeStringToGB(sizeString);
        var decayFactor = 1 - Math.pow(10, -weeks / 52);
        var seederFactor = 1 + Math.sqrt(2) * Math.pow(10, -(numOfSeeders) / 6);
        var magicNumber = decayFactor * size * seederFactor;
        var weeksCell = document.createElement('td');
        weeksCell.textContent = Math.round(magicNumber);
        row.appendChild(weeksCell);
        var weeksCell2 = document.createElement('td');
        var weeksCell3 = document.createElement('td');

        var ggnumber = magicNumber / size;
        weeksCell2.textContent = ggnumber.toFixed(3);
        if (parseFloat(ggnumber) > 0.98) {
            if(extractedNumber != 0){
                weeksCell2.style.fontWeight = 'bold';
                weeksCell2.style.color = 'red';
            }
        }
        row.appendChild(weeksCell2);
        ggnumber = extractedNumber;
        //console.log(parseFloat(ggnumber));


        weeksCell3.textContent = ggnumber;
        if (parseFloat(ggnumber) > 0.73) {
            weeksCell3.style.fontWeight = 'bold';
            weeksCell3.style.color = 'red';
        }
        row.appendChild(weeksCell3);
        //console.log("【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【【");
        //console.log("周期是:" + weeks);
        //console.log("大小是:" + size);
        //console.log("做种人数是:" + numOfSeeders);
        //console.log("计算出的A值是:" + magicNumber);
    });
})();