Archive.org Filter

Advanced filter for Archive.org roms

  1. // ==UserScript==
  2. // @name Archive.org Filter
  3. // @namespace psx_chd_filter
  4. // @match *archive.org/download/*
  5. // @include *archive.org/download/*
  6. // @require https://code.jquery.com/jquery-3.6.0.min.js
  7. // @grant none
  8. // @version 1.1
  9. // @author Andrea Do
  10. // @description Advanced filter for Archive.org roms
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14.  
  15.  
  16. $(document).ready(function() {
  17. var suffixes = `<input type="checkbox" id="use_suffix"> Use suffixes<br>
  18. <div style="display: none;" id="display_boxes"><br>
  19. <strong>Generic</strong><br>
  20. <input type="checkbox" data-suffix="[a]" checked style="display: none;"> [a] Alternate<br>
  21. <input type="checkbox" data-suffix="[p]" checked style="display: none;"> [p] Pirate<br>
  22. <input type="checkbox" data-suffix="[b]" checked style="display: none;"> [b] Bad Dump (avoid these, they may not work!)<br>
  23. <input type="checkbox" data-suffix="[t]" checked style="display: none;"> [t] Trained<br>
  24. <input type="checkbox" data-suffix="[f]" checked style="display: none;"> [f] Fixed<br>
  25. <input type="checkbox" data-suffix="[T-]" checked style="display: none;"> [T-] OldTranslation<br>
  26. <input type="checkbox" data-suffix="[T+]" checked style="display: none;"> [T+] NewerTranslation<br>
  27. <input type="checkbox" data-suffix="[h]" checked style="display: none;"> [h] Hack<br>
  28. <input type="checkbox" data-suffix="[cr" checked style="display: none;"> [cr {x}] Cracked (by {x})<br>
  29. <input type="checkbox" data-suffix="(-)" checked style="display: none;"> (-) Unknown Year<br>
  30. <input type="checkbox" data-suffix="[o]" checked style="display: none;"> [o] Overdump<br>
  31. <input type="checkbox" data-suffix="[!]" checked style="display: none;"> [!] Verified Good Dump<br>
  32. <input type="checkbox" data-suffix="ZZZ_" checked style="display: none;"> ZZZ_ Unclassified<br>
  33. <input type="checkbox" data-suffix="(Unl)" checked style="display: none;"> (Unl) Unlicensed<br><br>
  34. <strong>Platform specific</strong><br>
  35. <input type="checkbox" data-suffix="[PC10]" checked style="display: none;"> NES - [PC10] PlayChoice 10<br>
  36. <input type="checkbox" data-suffix="[VS]" checked style="display: none;"> NES - [VS] Versus<br>
  37. <input type="checkbox" data-suffix="[BS]" checked style="display: none;"> SNES - [BS] BS Roms<br>
  38. <input type="checkbox" data-suffix="[SF]" checked style="display: none;"> SNES - [SF] Sufami Turbo<br>
  39. <input type="checkbox" data-suffix="[NP]" checked style="display: none;"> SNES - [NP] Nintendo Power<br>
  40. </div>`;
  41. var download_all = '<div id="download_all"><b>Attempt bulk download</b> <i>(think thrice before doing this!)</i></div>';
  42. var hide_demo = '<h3>Disc type</h3>Include demos: <input type="checkbox" checked id="demos"><br>Include multidisc: <input type="checkbox" checked id="multidisc"><br>';
  43. var countries = '<h3>Localization</h3>Country/Region: <select id="country"><option value=".">ALL</option><option value="anything_else">Uncategorized</option></select><br>';
  44. var size_limit = '<h3>Misc</h3>'+suffixes+'Size limit: <input style="max-width: 75px;" id="limit" type="number" placeholder="Size limit" value="50000">MB<div><span style="display: none;" id="stats"><h3>Stats</h3>Showing <span id="counter">0</span> file(s).<br>Total size: <span id="total_size">0</span>'+download_all+'</span></div>';
  45. $("h1").after(hide_demo+countries+size_limit);
  46. });
  47.  
  48. //waitForKeyElements("#total_size", actions);
  49.  
  50. function engine() {
  51. $(document).ready(function() {
  52. var country_list = ['Italy', 'France', 'Germany', 'Spain', 'Netherlands', 'Sweden', 'Denmark', 'Norway', 'Portugal', 'Japan', 'USA', 'Europe', 'UK'];
  53. country_list.sort();
  54. for(k=0; k < country_list.length; k++) {
  55. $("#country").append('<option value="('+country_list[k]+')">'+country_list[k]+'</option>');
  56. }
  57. $("#download_all").append('<br><button id="dl_all">Download all</button>');
  58. $("#dl_all").click(function() {
  59. var exts = ['chd', 'zip', '7z', 'nes', 'sfc'];
  60. var sels = "";
  61. var selectors = "";
  62. for(e=0; e < exts.length; e++) {
  63. if(e==exts.length-1) {
  64. sels+=".directory-listing-table [href$='."+exts[e]+"']:visible";
  65. } else{
  66. sels+=".directory-listing-table [href$='."+exts[e]+"']:visible, ";
  67. }
  68. }
  69. selectors = sels;
  70. var len = $(selectors).length;
  71. if(len > 20) {
  72. var ask = confirm("This will open "+len+" tabs! Are you sure?");
  73. if(ask == true) {
  74. $(selectors).each(function() {
  75. var url = encodeURIComponent(window.location.href+"/"+$(this).attr("href"));
  76. window.open(decodeURIComponent(url));
  77. });
  78. }
  79. } else {
  80. $(selectors).each(function() {
  81. var url = encodeURIComponent(window.location.href+"/"+$(this).attr("href"));
  82. window.open(decodeURIComponent(url));
  83. });
  84. }
  85. });
  86.  
  87. $("input, select").click(function() {
  88. var sum = 0;
  89. $("#stats").show();
  90. $("tr").show();
  91. var exts = ['chd', 'zip', '7z', 'nes', 'sfc'];
  92. var sels = "";
  93. var selectors = "";
  94. for(e=0; e < exts.length; e++) {
  95. if(e==exts.length-1) {
  96. sels+=".directory-listing-table [href$='."+exts[e]+"']:visible";
  97. } else{
  98. sels+=".directory-listing-table [href$='."+exts[e]+"']:visible, ";
  99. }
  100. }
  101. selectors = sels;
  102. // Filter countries
  103. var country = $("#country option:selected").val();
  104. if(country === "anything_else") {
  105. for(k=0; k < country_list.length; k++) {
  106. $(selectors).each(function() {
  107. if($(this).text().indexOf(country_list[k]) > -1) {
  108. $(this).closest("tr").hide();
  109. } else {
  110. $(this).closest("tr").show();
  111. }
  112. });
  113. }
  114. } else {
  115. $(selectors).each(function() {
  116. if($(this).text().indexOf(country) <= -1) {
  117. $(this).closest("tr").hide();
  118. } else {
  119. $(this).closest("tr").show();
  120. }
  121. });
  122. }
  123. // Size limit
  124. var limit = parseInt($("#limit").val());
  125. var this_size = 0;
  126. $("tr td:nth-child(3):visible").each(function() {
  127. if($(this).text().indexOf("M") > -1) {
  128. this_size = ($(this).text().split("M")[0]*1);
  129. } else if($(this).text().indexOf("G") > -1) {
  130. this_size = ($(this).text().split("G")[0]*1024);
  131. } else if($(this).text().indexOf("K") > -1) {
  132. this_size = ($(this).text().split("K")[0]*0.001);
  133. }
  134. if(this_size <= limit) {
  135. $(this).closest("tr").show();
  136. } else {
  137. $(this).closest("tr").hide();
  138. }
  139. });
  140. // Show demos
  141. if($("#demos").is(':checked')) {
  142. $("tr:visible").show();
  143. } else {
  144. $(selectors).each(function() {
  145. if($(this).text().indexOf("(Demo)") > -1) {
  146. $(this).closest("tr").hide();
  147. }
  148. });
  149. }
  150. // Show Multidisc
  151. if($("#multidisc").is(':checked')) {
  152. $("tr:visible").show();
  153. } else {
  154. $(selectors).each(function() {
  155. if($(this).text().indexOf("(Disc ") > -1) {
  156. $(this).closest("tr").hide();
  157. }
  158. });
  159. }
  160. // Suffixes
  161. if($("#use_suffix").is(":checked")) {
  162. $("[data-suffix]").show();
  163. $("#display_boxes").show();
  164. $(selectors).each(function() {
  165. var this_rom = $(this);
  166. $("[data-suffix]:checked").each(function() {
  167. var attr = $(this).attr('data-suffix');
  168. if(this_rom.text().indexOf(attr) > -1) {
  169. this_rom.closest("tr").show();
  170. return false;
  171. } else {
  172. this_rom.closest("tr").hide();
  173. }
  174. });
  175. });
  176. } else {
  177. $("[data-suffix]").hide();
  178. $("#display_boxes").hide();
  179. }
  180. // Extensions
  181.  
  182. // Sum
  183. $("tr td:nth-child(3):visible").each(function() {
  184. var this_size = 0;
  185. var size_arr = [['M', 1], ['G', 1024], ['K', 0.001]];
  186. for(s=0; s < size_arr.length; s++) {
  187. if($(this).text().indexOf(size_arr[s][0]) > -1) {
  188. this_size = $(this).text().split(size_arr[s][0])[0]*size_arr[s][1];
  189. }
  190. }
  191. sum+=this_size;
  192. });
  193. // Stats
  194. $("#counter").text($(selectors).length);
  195. $("#total_size").text(sum.toFixed(2)+" MB ("+(sum/1024).toFixed(2)+" GB)");
  196. });
  197. });
  198. }
  199.  
  200. engine();