KAT - Toggle All Folders

Adds a button to expand/minimise all folders in a torrent on KAT

  1. // ==UserScript==
  2. // @name KAT - Toggle All Folders
  3. // @namespace ToggleAll
  4. // @version 1.21
  5. // @description Adds a button to expand/minimise all folders in a torrent on KAT
  6. // @match http://kat.cr/*.html
  7. // @match https://kat.cr/*.html
  8. // @exclude http://kat.cr/tos.html
  9. // @exclude https://kat.cr/tos.html
  10. // ==/UserScript==
  11.  
  12. $(".folderopen:first").attr("class", "folder");
  13. $('button[id$="AllFolders"]').remove();
  14. var temp = $('a[href^="javascript:getFiles"]:first').attr("href");
  15. var subfolder = $('table[id$="_1"]:first').attr("id");
  16. if (temp != undefined)
  17. {
  18. temp = temp.split(", ");
  19. morelink = temp[0] + ", " + temp[1];
  20. var pattern = new RegExp(";$");
  21. if (pattern.test(morelink)) // if morelink is found in root directory
  22. {
  23.  
  24. if (subfolder != undefined) // if subfolder is found
  25. {
  26. $(".torrent_files").prepend('<button id="Toggle" class="icon16 textButton" style="margin-right:5px; pointer-events: none; cursor: not-allowed;"><span></span>Toggle Folders</button>');
  27. $('<center id="loading" style="margin-top:10px"><i>Please wait before expanding the folders</i></center>').insertBefore(".data:first");
  28. }
  29. }
  30. else // if morelink is found in a sub folder
  31. {
  32. morelink = morelink + ");"
  33. $(".torrent_files").prepend('<button id="Toggle" class="icon16 textButton" style="margin-right:5px; pointer-events: none; cursor: not-allowed;"><span></span>Toggle Folders</button>');
  34. $('<center id="loading" style="margin-top:10px"><i>Please wait before expanding the folders</i></center>').insertBefore(".data:first");
  35. }
  36. window.open(morelink, "_self");
  37. }
  38. else // if no morelink is found
  39. {
  40. if (subfolder != undefined) // if subfolder is found
  41. {
  42. $(".torrent_files").prepend('<button id="Toggle" class="icon16 textButton" style="margin-right:5px;"><span></span>Toggle Folders</button>');
  43. }
  44. // if no subfolder (or morelink) is found
  45. }
  46. var count = $('table[id^="ul_"][id!="ul_top"]').length;
  47. var timer = count * 10;
  48. if (timer < 500 ) { timer = 500; }
  49.  
  50. setTimeout(function()
  51. {
  52. $('.torrent_files').bind("DOMSubtreeModified",function()
  53. {
  54. $("#loading").remove();
  55. $("#Toggle").removeAttr("style");
  56. $("#Toggle").css("margin-right", "5px");
  57. $("#ul_top").css("display", "block");
  58. });
  59. }, timer);
  60.  
  61. $("#Toggle").click( function()
  62. {
  63. $('span[class^="folder"][class!="foldericon"]').each(function()
  64. {
  65. if ($(this).attr("class") == "folder")
  66. {
  67. $(this).attr("class", "folderopen");
  68. }
  69. else
  70. {
  71. $(this).attr("class", "folder");
  72. }
  73. });
  74. $('table[id^="ul_"][id!="ul_top"]').after(function(ind)
  75. {
  76. if ($(this).css("display") == "none")
  77. {
  78. $(this).css("display", "block");
  79. }
  80. else
  81. {
  82. $(this).css("display", "none");
  83. }
  84. });
  85. });