GA forums tree

Позволяет "сворачивать" и "разворачивать" основные разделы форума "Глобальная авантюра" по принципу дерева.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        GA forums tree
// @namespace   glav.su
// @description Позволяет "сворачивать" и "разворачивать" основные разделы форума "Глобальная авантюра" по принципу дерева.
// @include     http://glav.su/forum/
// @include     https://glav.su/forum/
// @version     1.1
// @grant       none
// ==/UserScript==
//Работа с Cookie
function setCookie(name, value, options) {
	options = options || {};
	var expires = options.expires;
	if (typeof expires == "number" && expires) {
		var d = new Date();
		d.setTime(d.getTime() + expires * 1000);
		expires = options.expires = d;
	}
	if (expires && expires.toUTCString) {
		options.expires = expires.toUTCString();
	}
	value = encodeURIComponent(value);
	var updatedCookie = name + "=" + value;
	for (var propName in options) {
		updatedCookie += "; " + propName;
		var propValue = options[propName];
		if (propValue !== true) {
			updatedCookie += "=" + propValue;
		}
	}
	document.cookie = updatedCookie;
}
function getCookie(name) {
	var matches = document.cookie.match( new RegExp("(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)") );
	return matches ? decodeURIComponent(matches[1]) : undefined;
}
//Объект настроек
var settings = ({
	cook: 'ga_forums_tree',
	values: {},
	load: function(){
		try{
			this.values = JSON.parse( getCookie(this.cook) );
		}catch(e){
			this.values = {};
			this.save();
		}
		return this;
	},
	save: function(){
		setCookie( this.cook, JSON.stringify(this.values), {expires: 100000000} );
	},
	set: function(key, value){
		this.values[key] = value;
		this.save();
	},
	get: function(key){
		if(typeof this.values[key] == 'undefined'){
			this.values[key] = 0;
			this.save();
		}
		return this.values[key];
	}
}).load();
//Форумы
$.each( $(".blueHeader.f"), function(fidx, ftable){
	$(ftable).prev("br").hide();
	var ftd = $(ftable).find(".blueHeaderTitle.fItem");
	if( $(ftd).find("a").length === 0 ) return true;
	var fkey = $(ftd).find("a").attr("href").replace(/^https?:\/\/glav\.su\/forum\/(.*?)\/$/,"$1"),
		fvisible = +( settings.get(fkey) );
	if(fvisible === 0) $(ftable).next().hide();
	$(ftable).attr("fkey", fkey);
	$("<span>&nbsp;</span>").prependTo($(ftd));
	$('<span fvisible="'+fvisible+'" fkey="'+fkey+'">' + ['[+]','[-]'][fvisible] + '</span>')
		.css({ 'cursor': "pointer", 'font-family': "monospace" })
		.click(function(){
			var fkey = $(this).attr("fkey"), fvisible = +$(this).attr("fvisible");
			fvisible = +(!fvisible);
			$(this).html(['[+]','[-]'][fvisible]).attr("fvisible", fvisible);
			settings.set(fkey, fvisible);
			$(".blueHeader.f[fkey='"+fkey+"']").next().toggle();
		})
		.prependTo($(ftd));
});