qbittorrent 状态栏显示数量和大小

在 webUI 状态栏显示选中种子信息,点击按钮刷新或双击按钮自动刷新

目前为 2024-01-15 提交的版本。查看 最新版本

// ==UserScript==
// @name         qbittorrent 状态栏显示数量和大小
// @name:en      show counts and sizes of selected for qBittorrent
// @namespace    localhost
// @version      2024-01-15
// @description  在 webUI 状态栏显示选中种子信息,点击按钮刷新或双击按钮自动刷新
// @description:en  show counts and sizes of selected torrents, auto refresh enabled.
// @author       flashlab
// @match        http://127.0.0.1:8080/
// @icon         https://www.qbittorrent.org/favicon.ico
// @license      MIT
// @grant        unsafeWindow
// @grant        GM_addStyle
// @run-at       document-end

// ==/UserScript==

(function() {
    'use strict';

    GM_addStyle(".spin{animation:1.5s linear infinite rotation}@keyframes rotation{from{transform:rotate(0)}to{transform:rotate(359deg)}}")
    window.addEventListener('load', function () {
        const icons = document.querySelectorAll("#mochaToolbar > a");
        const icon = icons[icons.length - 1];
        const newicon = icon.cloneNode(true);
        newicon.id = "triggerStatus";
        newicon.firstChild.src = "images/view-refresh.svg";
        newicon.firstChild.title = "双击启用自动更新状态栏";
        const refreshBtn = icon.insertAdjacentElement("afterend", newicon);
        const footerow = document.querySelector("#desktopFooter > table > tbody > tr");
        const bar = document.createElement("td");
        bar.className = "statusBarSeparator";
        footerow.insertAdjacentElement("afterbegin", bar);
        const info = document.createElement("td");
        info.id = "selectedStatus";
        const statusTd = footerow.insertAdjacentElement("afterbegin", info);
        const states= ['size', 'total_size', 'uploaded'];
        var statusKey = states[0];
        var autoRefresh;
        // refresh event
        refreshBtn.addEventListener("click", function(e) {
            updateSelected()
        });
        refreshBtn.addEventListener("dblclick", function(e) {
            this.firstChild.toggleClass("spin")
            if (autoRefresh) {
                window.clearInterval(autoRefresh);
                autoRefresh = null;
            } else {
                // refresh every second
                autoRefresh = window.setInterval(updateSelected,1000);
            }
        });
        // switch event
        statusTd.onclick = (function() {
            let i = 0;
            return function(){
                i = ++i%states.length;
                statusKey = states[i];
                updateSelected();
            };
        })();
        // update info
        function updateSelected() {
            const selectedRows = torrentsTable.selectedRowsIds();
            const rows = torrentsTable.getFilteredAndSortedRows();
            const counts = selectedRows.length;
            const sizes = unsafeWindow.qBittorrent.Misc.friendlyUnit(selectedRows.reduce(
                (sum, hash) => rows[hash].full_data[statusKey] + sum, 0)
            )
            statusTd.textContent = `${sizes} ${statusKey} of ${counts}`
        }
    })
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址