Greasy Fork

Greasy Fork is available in English.

AvistaZ Bonus Point Plus+

Adds a "Shortfall" and "Time Calculation" to Exchange table, Adds BP per second, minute,...

当前为 2023-12-17 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AvistaZ Bonus Point Plus+
// @namespace    https://github.com/
// @homepage     https://github.com
// @version      0.1
// @author       Roy
// @description  Adds a "Shortfall" and "Time Calculation" to Exchange table, Adds BP per second, minute,...
// @match        https://avistaz.to/profile/*/bonus
// @icon         https://avistaz.to/images/avistaz-favicon.png
// @grant        none
// @license      MIT
// ==/UserScript==


(function () {
    'use strict';

    function createCalculationTable(pointsPerHour) {
        var pointsPerSecond = pointsPerHour / 3600;
        var pointsPerMinute = pointsPerHour / 60;
        var pointsPerDay = pointsPerHour * 24;
        var pointsPerWeek = pointsPerDay * 7;
        var pointsPerMonth = pointsPerDay * 30;
        var pointsPerYear = pointsPerDay * 365;

        var table = document.createElement('table');
        table.style.borderCollapse = 'collapse';
        table.style.marginTop = '10px';
        table.style.width = '100%';

        var tableHeader = table.createTHead();
        var headerRow = tableHeader.insertRow();
        var headerCellLabel = headerRow.insertCell();
        var headerCellValue = headerRow.insertCell();
        headerCellLabel.style.backgroundColor = 'lightblue';
        headerCellLabel.style.padding = '10px';
        headerCellValue.style.backgroundColor = 'lightblue';
        headerCellValue.style.padding = '10px';
        headerCellLabel.innerHTML = 'Calculation';
        headerCellValue.innerHTML = 'Value';

        var tableBody = table.createTBody();

        function addRow(label, value) {
            var row = tableBody.insertRow();
            var cellLabel = row.insertCell(0);
            var cellValue = row.insertCell(1);
            cellLabel.innerHTML = label;
            cellValue.innerHTML = value.toFixed(2);
            cellLabel.style.textAlign = 'left';
            cellValue.style.textAlign = 'right';
            cellLabel.style.paddingLeft = '10px';
            cellValue.style.paddingRight = '10px';
        }

        addRow('Points Per Second', pointsPerSecond);
        addRow('Points Per Minute', pointsPerMinute);
        addRow('Points Per Hour', pointsPerHour);
        addRow('Points Per Day', pointsPerDay);
        addRow('Points Per Week', pointsPerWeek);
        addRow('Points Per Month', pointsPerMonth);
        addRow('Points Per Year', pointsPerYear);

        return table;
    }

    function addCalculationColumn() {
        var pointsPerHour = parseFloat(document.querySelector('td:nth-child(3) strong').textContent);
        const header = document.querySelector('div > div > .col-sm-8 > table > thead > tr');

        if (header) {
            const shortfallHeaderCell = document.createElement('th');
            shortfallHeaderCell.textContent = 'Shortfall';
            header.querySelector('th:nth-child(2)').after(shortfallHeaderCell);

            const timeCalculationHeaderCell = document.createElement('th');
            timeCalculationHeaderCell.textContent = 'Time Calculation';
            shortfallHeaderCell.after(timeCalculationHeaderCell);
        }

        const tbody = document.querySelector('div > div > .col-sm-8 > table > tbody');
        const trimValueElement = document.querySelector('h2');
        const trimValue = parseFloat(trimValueElement.textContent.replace(/[^\d.]/g, '')) || 0;

        function formatTime(hours) {
            const months = Math.floor(hours / (30 * 24));
            const days = Math.floor((hours % (30 * 24)) / 24);
            const remainingHours = Math.round(hours % 24);
            let result = '';

            if (months > 0) {
                result += `${months} month${months > 1 ? 's' : ''}, `;
            }

            if (days > 0) {
                result += `${days} day${days > 1 ? 's' : ''}, `;
            }

            if (remainingHours > 0) {
                result += `${remainingHours} hour${remainingHours > 1 ? 's' : ''}`;
            }

            return result.trim();
        }

        if (tbody) {
            const rows = tbody.querySelectorAll('tr');
            rows.forEach((row, index) => {
                const pointsCell = row.querySelector('td:nth-child(2)');
                const pointsValue = parseInt(pointsCell.textContent.replace(/,/g, ''), 10);
                const shortfallValue = Math.max(pointsValue - trimValue, 0).toFixed(0);

                const shortfallCell = document.createElement('td');
                shortfallCell.textContent = shortfallValue;
                pointsCell.after(shortfallCell);

                const timeCalculationValue = shortfallValue / pointsPerHour;
                const timeCalculationCell = document.createElement('td');
                timeCalculationCell.textContent = formatTime(timeCalculationValue);
                shortfallCell.after(timeCalculationCell);
            });
        }
    }

    var targetElement = document.querySelector('div > div .well-sm > h3');

    if (targetElement) {
        var pointsPerHour = parseFloat(document.querySelector('td:nth-child(3) strong').textContent);
        var calculationTable = createCalculationTable(pointsPerHour);
        targetElement.parentNode.insertBefore(calculationTable, targetElement.nextSibling);
    }

    addCalculationColumn();
})();