taro's baraag unspoiler

remove spoiler from media tabs

  1. // ==UserScript==
  2. // @name taro's baraag unspoiler
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description remove spoiler from media tabs
  6. // @author You
  7. // @match https://baraag.net/*/media
  8. // @require http://code.jquery.com/jquery-3.4.1.min.js
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=baraag.net
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. let shouldCheck = false;
  15. let previousScroll = 0;
  16.  
  17.  
  18. function removeSpoilers(){ // unfortunately i am too lazy to not use jquery for this
  19. $(".account-gallery__item__icons").each(function(i, obj) { //obj = DOM element
  20. $(obj).click();
  21. }
  22. )}
  23.  
  24. function waitForElm(selector) { //.on('appears') doesn't run if the object doesn't exist yet...
  25. return new Promise(resolve => {
  26.  
  27. const observer = new MutationObserver(mutations => {
  28. if (document.querySelector(selector)) {
  29. resolve(document.querySelector(selector));
  30. observer.disconnect();
  31. }
  32. });
  33.  
  34. observer.observe(document.body, {
  35. childList: true,
  36. subtree: true
  37. });
  38. });
  39. }
  40. waitForElm('.account-gallery__item').then(()=>{ removeSpoilers(); });
  41.  
  42. window.onscroll = function(ev) {
  43.  
  44. if (previousScroll < window.innerHeight + window.pageYOffset && shouldCheck) {shouldCheck = false; removeSpoilers(); } //very ugly but i dont want it running every scroll... might as well have it only when going down
  45.  
  46. if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight) {
  47. previousScroll = window.innerHeight + window.pageYOffset;
  48. shouldCheck = true;
  49.  
  50. console.log("Reached bottom of the page. Next scroll will clean...");
  51. $(".load-more").click();
  52. }
  53. };