Advertisement
AHOHNMYC

Riot spoilerator

Jan 13th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Riot spoilerator
  3. // @namespace    azaza?
  4. // @version      0.0.0.0.0.0.0.0
  5. // @description  spoileraze teh wrld!
  6. // @author       AHOHNMYC
  7. // @match        https://riot.im/app/*
  8. // @match        https://riot.im/develop/*
  9. // @grant        GM_addStyle
  10. // ==/UserScript==
  11.  
  12. GM_addStyle(`
  13. spoiler {
  14.     background: #666;
  15.     color: #666;
  16.     padding: .3em;
  17.     transition: all .2s ease;
  18. }
  19. spoiler * {transition: opacity .2s ease}
  20. spoiler blockquote {display: inline-block; margin-bottom: 0 !important; color: #DDD !important}
  21. spoiler:not(:hover) * {opacity: 0}
  22. spoiler:hover {color: #DDD;}
  23. `);
  24.  
  25. function spoileraze() {
  26.     document.querySelectorAll('.mx_EventTile_body').forEach( node=>{
  27.         let close = true, text = node.innerHTML;
  28.  
  29.         text = text.replace(/(<p>%%<\/p>|%%)/g, ()=>{close=!close; return '<'+(close?'/':'')+'spoiler>';});
  30.         text = text.replace(/\[(\/?)s(poiler)?\]/g, '<$1spoiler>');
  31.  
  32.         if (text != node.innerHTML) node.innerHTML = text;
  33.     });
  34. }
  35.  
  36. let currMesgListEl = {};
  37. function init_() {
  38.     if (!document.querySelector('.mx_RoomView_messageListWrapper')) return;
  39.  
  40.     clearInterval(initIn);
  41.     initIn=0;
  42.  
  43.     if (currMesgListEl == document.querySelector('.mx_RoomView_MessageList')) return;
  44.     currMesgListEl = document.querySelector('.mx_RoomView_MessageList');
  45.  
  46.     spoileraze();
  47.     new MutationObserver(spoileraze).observe(currMesgListEl, { childList: true });
  48. }
  49.  
  50. let initIn = 0;
  51. function init() {
  52.     if (!initIn) initIn = setInterval(init_, 1000);
  53. }
  54.  
  55. addEventListener('click', init);
  56. init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement