Set qBittorrent Queue order

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

  1. // ==UserScript==
  2. // @name Set qBittorrent Queue order
  3. // @namespace http://tampermonkey.net/
  4. // @version v0.2
  5. // @description Set torrents queue order by sort on column attribute in qBittorrent.
  6. // @author me
  7. // @match http://localhost:8080/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=undefined.localhost
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Create a button element
  17. var button = document.createElement("button");
  18.  
  19. // Set button attributes and styles
  20. button.innerHTML = "<b>Set Queue Order</b> <br /> As your current ordered table";
  21. button.style.position = "fixed";
  22. button.style.right = "10px"; // Adjust the number of pixels from the right
  23. button.style.top = "20%"; // Vertical alignment in the middle
  24. button.style.transform = "translateY(-50%)";
  25. button.style.border = "2px solid red";
  26. button.style.backgroundColor = "orange";
  27. button.style.padding = "30px";
  28. button.style.cursor = "pointer";
  29.  
  30. // Add click event listener
  31. button.addEventListener("click", sortTable);
  32.  
  33. // Append the button to the body
  34. document.body.appendChild(button);
  35.  
  36.  
  37. // 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
  38. // 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.
  39. function sortTable(){
  40. // creates a sorting status div element
  41. var sortingNotification = document.createElement("div");
  42. sortingNotification.innerHTML = "<b>Setting queue order...</b>";
  43. sortingNotification.style.position = "fixed";
  44. sortingNotification.style.right = "10px"; // Adjust the number of pixels from the right
  45. sortingNotification.style.top = "30%"; // Vertical alignment in the middle
  46. sortingNotification.style.transform = "translateY(-50%)";
  47. sortingNotification.style.color = "black";
  48. sortingNotification.style.backgroundColor = "yellow";
  49. sortingNotification.style.padding = "20px 57px 20px 57px";
  50.  
  51. // Append status div to the body
  52. document.body.appendChild(sortingNotification);
  53. // Gets current table rows
  54. var tableRows = document.querySelectorAll("#torrentsTableDiv > table > tbody > tr");
  55. // Loops over each row
  56. tableRows.forEach(function(row, index, array){
  57. // Qbittorrent move to bottom of queue button
  58. const orderButton = document.querySelector("#bottomPrioButton");
  59.  
  60. setTimeout(function(){
  61.  
  62. row.click();
  63. orderButton.click();
  64.  
  65. if(index === array.length - 1){
  66. sortingNotification.style.padding = "20px 99px 20px 99px";
  67. sortingNotification.innerHTML = "<b>DONE!</b>";
  68. sortingNotification.style.backgroundColor = "lime";
  69. }
  70.  
  71. },index * 1000);
  72.  
  73.  
  74. });
  75. }
  76. })();