Last active
May 15, 2019 12:42
-
-
Save gsarig/31b4be67cbdb4e1c4fdc65e2cf9c42da to your computer and use it in GitHub Desktop.
A Greasemonkey script which adds a button to batch reveal spoilers on insomnia.gr. Spoiler morghulis!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Spoilers toggler for insomnia.gr | |
// @match https://www.insomnia.gr/* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js | |
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
waitForKeyElements('#elPostFeed', loadSpoilerToggler); | |
function loadSpoilerToggler() { | |
const spoilers = document.querySelectorAll('.ipsType_normal .ipsSpoiler'); | |
let i; | |
if (spoilers.length) { | |
if (!document.querySelector('.gm-spoilers')) { | |
const css = `.gm-spoilers { | |
opacity: 0.4; | |
font-weight:100; | |
font-size:12px !important; | |
background: rgba(0,0,0,0.9); | |
color: #fff; | |
position:fixed; | |
bottom: 10px; | |
right:10px; | |
border:0; | |
padding:10px; | |
border-radius:5px; | |
cursor:pointer; | |
} | |
.gm-spoilers:hover { | |
opacity:1; | |
} | |
.gm-spoilers.open{ | |
background: red; | |
};`; | |
const head = document.head || document.getElementsByTagName('head')[0]; | |
const style = document.createElement('style'); | |
style.appendChild(document.createTextNode(css)); | |
head.appendChild(style); | |
const btn = document.createElement('button'); | |
btn.innerHTML = 'ΚΛΕΙΣΤΑ SPOILERS'; | |
document.body.appendChild(btn); | |
btn.classList.add('gm-spoilers'); | |
} | |
toggleSpoilers(spoilers, document.querySelector('.gm-spoilers')); | |
} | |
} | |
function toggleSpoilers(spoilers, spoilerBtn) { | |
if (spoilerBtn.classList.contains('open')) { | |
loopThroughSpoilers(spoilers); | |
} | |
} | |
function loopThroughSpoilers(spoilers) { | |
for (i = 0; i < spoilers.length; i++) { | |
const spoilerHeader = spoilers[i].querySelector('.ipsSpoiler_header'); | |
spoilerHeader.click(); | |
} | |
} | |
let btn = document.querySelector('.gm-spoilers'); | |
let btnInitialTxt = btn.innerHTML; | |
btn.addEventListener('click', function () { | |
loopThroughSpoilers(document.querySelectorAll('.ipsType_normal .ipsSpoiler')); | |
if (btn.classList.contains('open')) { | |
btn.classList.remove('open'); | |
btn.innerHTML = btnInitialTxt; | |
} else { | |
btn.classList.add('open'); | |
btn.innerHTML = 'ΑΝΟΙΧΤΑ SPOILERS'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment