Set qBittorrent Queue order

Set torrents queue order by sort on column attribute in qBittorrent.

当前为 2024-01-03 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Set qBittorrent Queue order
// @namespace    http://tampermonkey.net/
// @version      v0.2
// @description  Set torrents queue order by sort on column attribute in qBittorrent.
// @author       me
// @match        http://localhost:8080/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=undefined.localhost
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Create a button element
    var button = document.createElement("button");

    // Set button attributes and styles
    button.innerHTML = "<b>Set Queue Order</b> <br /> As your current ordered table";
    button.style.position = "fixed";
    button.style.right = "10px"; // Adjust the number of pixels from the right
    button.style.top = "20%"; // Vertical alignment in the middle
    button.style.transform = "translateY(-50%)";
    button.style.border = "2px solid red";
    button.style.backgroundColor = "orange";
    button.style.padding = "30px";
    button.style.cursor = "pointer";

    // Add click event listener
    button.addEventListener("click", sortTable);

    // Append the button to the body
    document.body.appendChild(button);


    // Function to sort the queue order by the current sorted table. Be aware that the sorting uses the bottom of the queue, so if let's say you have 100 torrents in multiple categories, and you want to sort just e.g. 40 torrents in a category
    // their queue order will be 41, 42, 43, ..., 100, if you want to move them at the top of the queue just select all of them and click the "Move to the top of the queue" Button  in the Qbittorrent top toolbar.
    function sortTable(){
        // creates  a sorting status div element
        var sortingNotification = document.createElement("div");
        sortingNotification.innerHTML = "<b>Setting queue order...</b>";
        sortingNotification.style.position = "fixed";
        sortingNotification.style.right = "10px"; // Adjust the number of pixels from the right
        sortingNotification.style.top = "30%"; // Vertical alignment in the middle
        sortingNotification.style.transform = "translateY(-50%)";
        sortingNotification.style.color = "black";
        sortingNotification.style.backgroundColor = "yellow";
        sortingNotification.style.padding = "20px 57px 20px 57px";

        // Append status div to the body
        document.body.appendChild(sortingNotification);
        // Gets current table rows
        var tableRows = document.querySelectorAll("#torrentsTableDiv > table > tbody > tr");
        // Loops over each row
        tableRows.forEach(function(row, index, array){
            // Qbittorrent move to bottom of queue button
            const orderButton = document.querySelector("#bottomPrioButton");

            setTimeout(function(){

                row.click();
                orderButton.click();

                if(index === array.length - 1){
                sortingNotification.style.padding = "20px 99px 20px 99px";
                sortingNotification.innerHTML = "<b>DONE!</b>";
                sortingNotification.style.backgroundColor = "lime";
            }

            },index * 1000);


        });
    }
})();