GameFAQs Collapsible Spoilers

By OTACON120 Last update May 23, 2012 — Installed 493 times.

There are 1 previous version of this script.

// ==UserScript==
// @name        GameFAQs Collapsible Spoilers
// @namespace   OTACON120
// @author      OTACON120
// @version     1.0
// @description Replaces GameFAQs obscured-text spoilers with collapsible spoilers
// @updateURL   http://userscripts.org/scripts/source/134043.meta.js
// @downloadURL http://userscripts.org/scripts/source/134043.user.js
// @website     http://otacon120.com/user-scripts/gamefaqs-related/collapsible-spoilers
// @include     http://www.gamefaqs.com/boards/*-*
// @match       http://www.gamefaqs.com/boards/*-*
// ==/UserScript==
var newSpoilerCSS = document.createElement('style'),
	i,
	spoilers = document.getElementsByClassName('fspoiler'),
	revealSpoilers = [],
	x;

newSpoilerCSS.textContent = '#content .fspoiler, #content .fspoiler:hover, #content .fspoiler a, #content .fspoiler a:hover {background: transparent; color: inherit;} #content .fspoiler {display: inline-block; width: 0; height: 0; overflow: hidden;} .hideSpoiler {border-bottom: 1px dotted; cursor: pointer;}';

document.head.appendChild(newSpoilerCSS);

for (i = 0; i < spoilers.length; i++) {
	spoilers[i].id = 'spoiler-' + i;
	revealSpoilers[i] = document.createElement('button');
	revealSpoilers[i].id = 'revealSpoiler-' + i;
	revealSpoilers[i].onclick = function() {
		if (this.id.indexOf('revealSpoiler') != -1) {
			x = this.id.replace('revealSpoiler-', '');
			spoilers[x].style.display = 'inline';
			spoilers[x].innerHTML = ' ' + spoilers[x].innerHTML;
			spoilers[x].className += ' hideSpoiler';
			this.id = 'hideSpoiler-' + x;
			this.textContent = 'X';
			this.title = spoilers[x].title = 'Click to hide this spoiler';
		} else if (this.id.indexOf('hideSpoiler') != -1) {
			x = this.id.replace('hideSpoiler-', '');
			spoilers[x].removeAttribute('style');
			spoilers[x].removeAttribute('title');
			this.removeAttribute('title');
			spoilers[x].className = 'fspoiler';
			this.id = 'revealSpoiler-' + x;
			this.textContent = 'Reveal Spoiler';
		}
	}
	revealSpoilers[i].textContent = 'Reveal Spoiler';
	spoilers[i].parentNode.insertBefore(revealSpoilers[i], spoilers[i]);
	spoilers[i].onclick = function(){
		if (this.className.indexOf('hideSpoiler') != -1) {
			x = this.id.replace('spoiler-', '');
			this.removeAttribute('style');
			this.removeAttribute('title');
			revealSpoilers[x].removeAttribute('title');
			this.className = 'fspoiler';
			revealSpoilers[x].id = 'revealSpoiler-' + x;
			revealSpoilers[x].textContent = 'Reveal Spoiler';
		}
	}
}