You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

  1. // ==UserScript==
  2. // @name SugoiMusic Clickable Category Icons
  3. // @namespace http://sugoimusic.me
  4. // @version 0.1
  5. // @description Changes content type specified in search by clicking on the category icons
  6. // @author herbert
  7. // @icon https://sugoimusic.me/favicon.ico
  8. // @match https://sugoimusic.me/torrents.php*
  9. // @grant none
  10. // ==/UserScript==
  11. const categoryMap = new Map();
  12. categoryMap.set('cats_album', 1);
  13. categoryMap.set('cats_ep', 2);
  14. categoryMap.set('cats_single', 3);
  15. categoryMap.set('cats_bluray', 4);
  16. categoryMap.set('cats_dvd', 5);
  17. categoryMap.set('cats_pv', 6);
  18. categoryMap.set('cats_musicperformance', 7);
  19. categoryMap.set('cats_tvmusic', 8);
  20. categoryMap.set('cats_tvvariety', 9);
  21. categoryMap.set('cats_tvdrama', 10);
  22. categoryMap.set('cats_pictures', 11);
  23. categoryMap.set('cats_misc', 12);
  24. function removeExistingCategoriesFromUrl(urlParams, categorySearchString) {
  25. let cleanedUrlParams = new URLSearchParams();
  26. for (let entry of urlParams.entries()) {
  27. if (!entry[0].startsWith(categorySearchString) && entry[0]!='page') {
  28. cleanedUrlParams.append(entry[0],entry[1]);
  29. }
  30. }
  31. return cleanedUrlParams;
  32. }
  33. (function () {
  34. 'use strict';
  35. let categorySearchString = 'filter_cat';
  36. let urlParams = new URLSearchParams(window.location.search);
  37. //Identify if we are on the torrent search or snatched/seeding/uploaded pages
  38. if (urlParams.has('type')) {
  39. categorySearchString = 'categories';
  40. }
  41. urlParams = removeExistingCategoriesFromUrl(urlParams, categorySearchString);
  42. let categoryIcons = document.querySelectorAll('div[class*="cats"]');
  43. for (let iconDiv of categoryIcons) {
  44. let newCat;
  45. for (let e of iconDiv.classList) {
  46. if (categoryMap.has(e)) {
  47. newCat = e;
  48. }
  49. }
  50. let newUrlParams = new URLSearchParams(urlParams)
  51. newUrlParams.append(categorySearchString + '[' + categoryMap.get(newCat) + ']','1');
  52. //Create new anchor wrapped around the div
  53. let url = window.location.pathname.split('?')[0];
  54. let parent = iconDiv.parentNode;
  55. let a = document.createElement('a');
  56. a.setAttribute('href', url + '?' + newUrlParams.toString())
  57. parent.replaceChild(a, iconDiv);
  58. a.appendChild(iconDiv);
  59. }
  60. })();