|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- // ==UserScript==
- // @name SugoiMusic Clickable Category Icons
- // @namespace http://sugoimusic.me
- // @version 0.1
- // @description Changes content type specified in search by clicking on the category icons
- // @author herbert
- // @icon https://sugoimusic.me/favicon.ico
- // @match https://sugoimusic.me/torrents.php*
- // @grant none
- // ==/UserScript==
-
- const categoryMap = new Map();
- categoryMap.set('cats_album', 1);
- categoryMap.set('cats_ep', 2);
- categoryMap.set('cats_single', 3);
- categoryMap.set('cats_bluray', 4);
- categoryMap.set('cats_dvd', 5);
- categoryMap.set('cats_pv', 6);
- categoryMap.set('cats_musicperformance', 7);
- categoryMap.set('cats_tvmusic', 8);
- categoryMap.set('cats_tvvariety', 9);
- categoryMap.set('cats_tvdrama', 10);
- categoryMap.set('cats_pictures', 11);
- categoryMap.set('cats_misc', 12);
-
- function removeExistingCategoriesFromUrl(urlParams, categorySearchString) {
- let cleanedUrlParams = new URLSearchParams();
- for (let entry of urlParams.entries()) {
- if (!entry[0].startsWith(categorySearchString) && entry[0]!='page') {
- cleanedUrlParams.append(entry[0],entry[1]);
- }
- }
- return cleanedUrlParams;
- }
-
- (function () {
- 'use strict';
- let categorySearchString = 'filter_cat';
- let urlParams = new URLSearchParams(window.location.search);
- //Identify if we are on the torrent search or snatched/seeding/uploaded pages
- if (urlParams.has('type')) {
- categorySearchString = 'categories';
- }
- urlParams = removeExistingCategoriesFromUrl(urlParams, categorySearchString);
- let categoryIcons = document.querySelectorAll('div[class*="cats"]');
- for (let iconDiv of categoryIcons) {
- let newCat;
- for (let e of iconDiv.classList) {
- if (categoryMap.has(e)) {
- newCat = e;
- }
- }
- let newUrlParams = new URLSearchParams(urlParams)
- newUrlParams.append(categorySearchString + '[' + categoryMap.get(newCat) + ']','1');
- //Create new anchor wrapped around the div
- let url = window.location.pathname.split('?')[0];
- let parent = iconDiv.parentNode;
- let a = document.createElement('a');
- a.setAttribute('href', url + '?' + newUrlParams.toString())
- parent.replaceChild(a, iconDiv);
- a.appendChild(iconDiv);
- }
- })();
|