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.

72 lines
2.0 KiB

  1. // ==UserScript==
  2. // @name SugoiMusic Filter Toggle
  3. // @namespace http://sugoimusic.me
  4. // @version 0.1
  5. // @description Modifies filter bar behavior on artist pages so that mutiple categories can be selected
  6. // @author herbert
  7. // @icon https://sugoimusic.me/favicon.ico
  8. // @match https://sugoimusic.me/artist.php?id=*
  9. // @grant none
  10. // ==/UserScript==
  11. function filter(e){
  12. if (e.getAttribute('selected') === 'true'){
  13. hideCategory(e);
  14. } else {
  15. showCategory(e);
  16. }
  17. apply_torrent_table_styling();
  18. }
  19. function showAll(e){
  20. let filterCats = document.querySelectorAll('li[id^="nav"]>a.filter-cat');
  21. console.log(filterCats);
  22. for (let element of filterCats){
  23. console.log(element);
  24. showCategory(element);
  25. }
  26. apply_torrent_table_styling();
  27. }
  28. function hideCategory(e) {
  29. let className = e.parentElement.getAttribute('id').replace('nav_','');
  30. if (e.closest('#discog_table')){
  31. $('.non_contrib_table .'+className).ghide();
  32. } else {
  33. $('.contrib_table .'+className).ghide();
  34. }
  35. e.setAttribute('selected',false);
  36. e.style.fontWeight = 'normal';
  37. }
  38. function showCategory(e) {
  39. let className = e.parentElement.getAttribute('id').replace('nav_','');
  40. if (e.closest('#discog_table')){
  41. $('.non_contrib_table .'+className).gshow();
  42. } else {
  43. $('.contrib_table .'+className).gshow();
  44. }
  45. e.setAttribute('selected',true);
  46. e.style.fontWeight = 'bold';
  47. }
  48. (function() {
  49. 'use strict';
  50. let filterAll = document.querySelector('a#nav_all');
  51. filterAll.removeAttribute('onclick');
  52. filterAll.setAttribute('href','#/');
  53. filterAll.addEventListener('click',function(){
  54. showAll(this);
  55. });
  56. let filterCats = document.querySelectorAll('li[id^="nav"]>a.filter-cat');
  57. for (let element of filterCats){
  58. element.removeAttribute('onclick');
  59. element.setAttribute('selected',true);
  60. element.setAttribute('href','#/');
  61. element.style.fontWeight = 'bold';
  62. element.addEventListener('click',function(event){
  63. filter(this);
  64. });
  65. }
  66. })();