// ==UserScript==
// @name Forum Collapse
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Collapseable forums on main listing page
// @author touch
// @match http*://forums.overclockers.co.uk*
// @grant none
// ==/UserScript==
(function() {
var cols = getCollapsed();
var ids = cols.split(",");
for(var i = 0; i <ids.length; i++) {
collapseView(ids[i]);
}
var titles = document.getElementsByClassName("nodeTitle");
for (var x = 0; x < titles.length; x++) {
if(titles[x].parentNode.className == "categoryText"){titles[x].prepend("+/- ");}
titles[x].addEventListener('click', toggleView, false);
}})();
function toggleView(evt){
if (evt.target !== this)
return;
if(evt.target.className.indexOf("collapsed") === -1)
{
evt.target.className += " collapsed";
evt.target.parentNode.parentNode.parentNode.childNodes[3].style.display = "none";
collapse(evt.target.parentNode.parentNode.parentNode.id.split(".")[1]);
}
else{
evt.target.className = evt.target.className.replace(" collapsed","");
evt.target.parentNode.parentNode.parentNode.childNodes[3].style.display = "block";
expand(evt.target.parentNode.parentNode.parentNode.id.split(".")[1]);
}
}
function collapseView(id){
var titles = document.getElementsByClassName("node_"+id);
for (var i = 0; i < titles.length; i++) {
titles[i].children[0].children[0].children[0].className += " collapsed";
titles[i].childNodes[3].style.display = "none";
}
}
function collapse(id) {
var col = getCollapsed();
col+=","+id;
document.cookie = "collapsed=" + col + ";path=/";
}
function expand(id) {
var col = getCollapsed();
var remove = ","+id;
var newcol = col.replace(remove, "");
document.cookie = "collapsed=" + newcol + ";path=/";
}
function getCollapsed() {
var name = "collapsed=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}