Lute: Current Page Statuses Alert Button

Adds a button to alert the current page term statuses

当前为 2024-05-09 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Lute: Current Page Statuses Alert Button
// @version      20240509
// @description  Adds a button to alert the current page term statuses
// @author       jamesdeluk
// @match        http://localhost:500*/read/*
// @grant        none
// @homepageURL  https://greasyfork.org/en/scripts/493338-lute-current-page-statuses-alert-button
// @supportURL   https://greasyfork.org/en/scripts/493338-lute-current-page-statuses-alert-button/feedback
// @namespace https://greasyfork.org/users/242246
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        const btn_statuses = document.createElement('button');
        btn_statuses.textContent = "%";
        btn_statuses.style.position = "fixed";
        btn_statuses.style.left = "0";
        btn_statuses.style.top = "50%";
        btn_statuses.style.transform = "translateY(-50%)";
        btn_statuses.style.margin = "0.1em";
        btn_statuses.style.padding = "0.1em 0.1em";
        btn_statuses.style.zIndex = "1000";
        btn_statuses.onclick = function() {
            const statusNames = {
                'status0': '?',
                'status1': '1',
                'status2': '2',
                'status3': '3',
                'status4': '4',
                'status5': '5',
                'status99': '✓',
                'status98': 'X'
            };
            let totalStatusCount = 0;
            let statusCounts = Object.keys(statusNames).map(status => {
                let count = document.getElementsByClassName(status).length;
                totalStatusCount += count;
                return {status: statusNames[status], count};
            });
            let total = `Total terms: ${totalStatusCount}\n`;
            // let results = 'Status Counts:\n';
            let results = '';
            // let bars = 'Visual Representation:\n';
            let bars = '';
            statusCounts.forEach(({status, count}) => {
                let percentage = (count / totalStatusCount) * 100;
                let barLength = Math.round(percentage / 5);
                let bar = new Array(barLength + 1).join('+');
                results += `${status.padEnd(2)} : ${String(count).padEnd(2)} (${percentage.toFixed(1)}%)\n`;
                bars += `${status.padEnd(2)} : ${bar}\n`;
            });
            alert(total + '\n' + results + '\n' + bars);
        };
        document.body.appendChild(btn_statuses);
    });

})();