🏠 Home 

NyaaDeadTorrents

A simple script to remove dead torrents from the browse section of Nyaa.


Install this script?
  1. // ==UserScript==
  2. // @name NyaaDeadTorrents
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.1
  5. // @description A simple script to remove dead torrents from the browse section of Nyaa.
  6. // @author Arjix
  7. // @include https://nyaa.si/*
  8. // @include https://sukebei.nyaa.si/*
  9. // @include https://meowinjapanese.cf/*
  10. // @require https://code.jquery.com/jquery-3.5.1.min.js
  11. // @grant GM.setValue
  12. // @grant GM.getValue
  13. // ==/UserScript==
  14. if (!localStorage.getItem("NyaaRemoveRule")) {
  15. localStorage.setItem("NyaaRemoveRule", "seeds")
  16. }
  17. function submitSetting() {
  18. let value = document.getElementById("removeDeadTorrentsRule").value
  19. localStorage.setItem("NyaaRemoveRule", value)
  20. }
  21. function removeTorrent(torrent, count) {
  22. torrent.parentNode.removeChild(torrent)
  23. console.log("Removed torrent with index of: " + count.toString())
  24. }
  25. window.addEventListener("load", function () {
  26. const title = document.querySelector("title").innerText
  27. const allMeta = document.head.querySelectorAll("meta")
  28. const desc = allMeta[allMeta.length - 1].content
  29. if ("Browse :: Nyaa" === title || desc === "Nyaa homepage" || "Browse :: Sukebei" === title || desc === "Sukebei homepage" || desc.includes("Search for ") || desc.includes("Torrents uploaded by ")) {
  30. let torrents = document.querySelectorAll(".table-responsive > table > tbody > tr")
  31. var torrentsCount = torrents.length
  32. let removeRule = localStorage.getItem("NyaaRemoveRule")
  33. for (let count = 0; count < torrents.length; count++) {
  34. let seeds = torrents[count].querySelector("td:nth-child(6)").innerText
  35. let leachers = torrents[count].querySelector("td:nth-child(7)").innerText
  36. if (seeds == "0" && removeRule == "seeds") {
  37. removeTorrent(torrents[count], count)
  38. torrentsCount = torrentsCount - 1
  39. } else if (leachers == "0" && removeRule == "leachers") {
  40. removeTorrent(torrents[count], count)
  41. torrentsCount = torrentsCount - 1
  42. } else if (seeds == "0" && leachers == "0" && removeRule == "both") {
  43. removeTorrent(torrents[count], count)
  44. torrentsCount = torrentsCount - 1
  45. }
  46. }
  47. if (torrentsCount <= 0) {
  48. let pagination = document.querySelectorAll("ul.pagination > li")
  49. let nextPage = pagination[pagination.length - 1].childNodes[0].href
  50. window.location.replace(nextPage)
  51. }
  52. } else if (document.location.href == "https://nyaa.si/profile") {
  53. if (localStorage.getItem("NyaaRemoveRule") == "seeds") {
  54. var choiceOne = "<option selected>"
  55. } else { var choiceOne = "<option>" }
  56. if (localStorage.getItem("NyaaRemoveRule") == "leachers") {
  57. var choiceTwo = "<option selected>"
  58. } else { var choiceTwo = "<option>" }
  59. if (localStorage.getItem("NyaaRemoveRule") == "both") {
  60. var choiceThree = "<option selected>"
  61. } else { var choiceThree = "<option>" }
  62. var settings = `<div class="row">
  63. <div class="form-group col-md-4">
  64. <p>DeadTorrent removeRule:
  65. <select id="removeDeadTorrentsRule">` +
  66. choiceOne + "seeds</option>" +
  67. choiceTwo + "leachers</option>" +
  68. choiceThree + "both</option>" +
  69. `</select></p>
  70. </div>
  71. </div>`
  72. $("#preferences-change > form > .row").first().after(settings)
  73. document.getElementById("submit_settings").addEventListener('click', () => { submitSetting(); }, false);
  74. }
  75. }, false)