Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Riot spoilerator
- // @namespace azaza?
- // @version 0.0.0.0.0.0.0.0
- // @description spoileraze teh wrld!
- // @author AHOHNMYC
- // @match https://riot.im/app/*
- // @match https://riot.im/develop/*
- // @grant GM_addStyle
- // ==/UserScript==
- GM_addStyle(`
- spoiler {
- background: #666;
- color: #666;
- padding: .3em;
- transition: all .2s ease;
- }
- spoiler * {transition: opacity .2s ease}
- spoiler blockquote {display: inline-block; margin-bottom: 0 !important; color: #DDD !important}
- spoiler:not(:hover) * {opacity: 0}
- spoiler:hover {color: #DDD;}
- `);
- function spoileraze() {
- document.querySelectorAll('.mx_EventTile_body').forEach( node=>{
- let close = true, text = node.innerHTML;
- text = text.replace(/(<p>%%<\/p>|%%)/g, ()=>{close=!close; return '<'+(close?'/':'')+'spoiler>';});
- text = text.replace(/\[(\/?)s(poiler)?\]/g, '<$1spoiler>');
- if (text != node.innerHTML) node.innerHTML = text;
- });
- }
- let currMesgListEl = {};
- function init_() {
- if (!document.querySelector('.mx_RoomView_messageListWrapper')) return;
- clearInterval(initIn);
- initIn=0;
- if (currMesgListEl == document.querySelector('.mx_RoomView_MessageList')) return;
- currMesgListEl = document.querySelector('.mx_RoomView_MessageList');
- spoileraze();
- new MutationObserver(spoileraze).observe(currMesgListEl, { childList: true });
- }
- let initIn = 0;
- function init() {
- if (!initIn) initIn = setInterval(init_, 1000);
- }
- addEventListener('click', init);
- init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement