ao3 series collapser

collapse works that are later than part 1 of a series

  1. // ==UserScript==
  2. // @name ao3 series collapser
  3. // @namespace https://greasyfork.org/en/users/36620
  4. // @version 0.5
  5. // @description collapse works that are later than part 1 of a series
  6. // @author scriptfairy
  7. // @include http://archiveofourown.org/*works*
  8. // @include https://archiveofourown.org/*works*
  9. // @exclude /https?://archiveofourown\.org/works/\d+/
  10. // @grant none
  11. // @run-at document-idle
  12. // ==/UserScript==
  13.  
  14. var serColStyle = document.createElement('style');
  15. serColStyle.innerHTML = '@keyframes hideSeries {from{opacity:1;} to {opacity:0.6;}} @keyframes showSeries {from{opacity:0.6;} to {opacity:1;}} .hideseries > * {display:none; animation: hideSeries 250ms ease-in-out both;} .hideseries>.series {display:block; opacity:0.6;} .showseries>*{display:block; animation: showSeries 250ms ease-in-out both;}';
  16. document.head.appendChild(serColStyle);
  17.  
  18. var series = document.querySelectorAll('li.blurb ul.series');
  19.  
  20. for (i=0; i<series.length; i++) {
  21. var serText = series[i].innerText;
  22. if (serText.search('Part 1 of') == -1) {
  23. series[i].parentNode.className += ' series-collapse hideseries';
  24. }
  25. }
  26.  
  27. var colSers = document.getElementsByClassName('series-collapse');
  28.  
  29. for (j=0; j<colSers.length; j++) {
  30. var colSer = colSers[j];
  31. colSer.onclick = function() {
  32. if (this.classList.contains('hideseries')) {
  33. this.classList.remove('hideseries');
  34. this.classList += ' showseries';
  35. } else {
  36. this.classList.remove('showseries');
  37. this.classList += ' hideseries';
  38. }
  39. };
  40. }