dailyhwm / HideInfo

// ==UserScript==
// @name HideInfo
// @version 1.2.2
// @author Ilovemycomp, Mefistophel_Gr, СтепнойВарварка
// @homepage https://greasyfork.org/ru/scripts/10659
// @description Сворачивает огромные списки Кланов, Достижений, Ресурсов, Статистики, Семьи, Личной информации... Сокращает отображаемый текст - чтобы видеть сразу Нужное. Спойлеры, свёрнутые по умолчанию, после загрузки страницы - можно развернуть нажав на них ЛКМ.
// @include /^https{0,1}:\/\/((www|qrator)\.(heroeswm|lordswm)\.(ru|com))\/(pl_info|pers_settings|clan_info)\.php.*/
// @grant none
// @license MIT
// ==/UserScript==
(function () {
	var s, all;

	if (document.location.pathname.includes('/pl_info.php')) {
		// Кланы
		var clan;
		var hide_clans = false;
		var b = document.querySelector('td.wb>a[href*="clan_info.php?id="]>b');
		if (b) {
			clan = b.parentNode.parentNode;
			clan.style.display = 'none';
			clan.parentNode.previousSibling.addEventListener('click', expandClans);
		}

		function expandClans() {
			if (hide_clans) {
				clan.style.display = 'none';
			} else {
				clan.style.display = '';
			}
			hide_clans = !hide_clans;
		}

		// Достижения
		var achiev;
		var hide_achiev = false;
		all = document.querySelectorAll("tbody > tr:nth-child(1) > td > b");
		s = false;
		for (var i in all)
			if (all[i].innerHTML == "Достижения") {
				s = all[i];
				break;
			}
		if (s) {
			achiev = s.parentNode.parentNode.nextSibling.childNodes[0];
			achiev.style.display = 'none';
			s.parentNode.parentNode.addEventListener('click', expandAchiev);
		}

		function expandAchiev() {
			if (hide_achiev) {
				achiev.style.display = 'none';
			} else {
				achiev.style.display = '';
			}
			hide_achiev = !hide_achiev;
		}

		// Семья
		var family;
		var hide_family = false;
		all = document.querySelectorAll("tbody > tr:nth-child(2) > td");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Семья: ") === 0) {
				s = all[i];
				break;
			}
		}
		if (s) {
			family = s;
			family.style.display = 'none';
			arr = family.parentNode.previousSibling.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes;
			if (arr.length > 2)
				arr[3].addEventListener('click', expandFamily);
			else
				arr[1].addEventListener('click', expandFamily);
		}

		function expandFamily() {
			if (hide_family)
				family.style.display = 'none';
			else
				family.style.display = '';
			hide_family = !hide_family;
		}

		// Ресурсы, умения, навыки
		var skills;
		var hide_skills = false;
		all = document.querySelectorAll("tbody > tr:nth-child(1) > td:nth-child(1) > b");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Ресурсы") === 0) {
				s = all[i];
				break;
			}
		}
		if (s.parentNode != null && s.parentNode.parentNode != null) {
			skills = s.parentNode.parentNode.nextSibling;
			skills.style.display = 'none';
			s.parentNode.addEventListener('click', expandSkills);
			s.parentNode.nextSibling.addEventListener('click', expandSkills);
			s.parentNode.nextSibling.nextSibling.addEventListener('click', expandSkills);
		}

		function expandSkills() {
			if (hide_skills)
				skills.style.display = 'none';
			else
				skills.style.display = '';
			hide_skills = !hide_skills;
		}

		// Статистика
		var stat;
		var hide_stat = false;
		all = document.querySelectorAll("td");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Статистика") === 0) {
				s = all[i];
				break;
			}
		}
		if (s.parentNode != null && s.parentNode.nextSibling != null) {
			stat = s.parentNode.nextSibling;
			stat.style.display = 'none';
			s.addEventListener('click', expandStat);
		}

		function expandStat() {
			if (hide_stat)
				stat.style.display = 'none';
			else
				stat.style.display = '';
			hide_stat = !hide_stat;
		}

		// Инфа
		var infa;
		var hide_infa = false;
		all = document.querySelectorAll("td");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Личная информация") === 0) {
				s = all[i];
				break;
			}
		}
		if (s.parentNode != null && s.parentNode.nextSibling != null) {
			infa = s.parentNode.nextSibling;
			infa.style.display = 'none';
			s.addEventListener('click', expandInfa);
		}

		// чтобы вкл автоскрытие инфы нужно раскоментить 146. чтобы выкл - закомментить 146 + поменять местами 151 с 153. изначально выкл.
		function expandInfa() {
			if (hide_infa)
				infa.style.display = 'none';
			else
				infa.style.display = '';
			hide_infa = !hide_infa;
		}

		// Валентинки
		var val;
		var hide_val = false;
		all = document.querySelectorAll("td");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Валентинки") === 0) {
				s = all[i];
				break;
			}
		}
		if (s) {
			val = s.parentNode.nextSibling;
			val.style.display = 'none';
			s.addEventListener('click', expandVal);

			function expandVal() {
				if (hide_val) {
					val.style.display = 'none';
				} else {
					val.style.display = '';
				}
				hide_val = !hide_infa;
			}
		}
		// Подарки защитник отечества
		var zash;
		var hide_zash = false;
		all = document.querySelectorAll("td");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Подарки") === 0) {
				s = all[i];
				break;
			}
		}
		if (s) {
			zash = s.parentNode.nextSibling;
			zash.style.display = 'none';
			s.addEventListener('click', expandZash);

			function expandZash() {
				if (hide_zash) {
					zash.style.display = 'none';
				} else {
					zash.style.display = '';
				}
				hide_zash = !hide_zash;
			}
		}
		// Лучшие отряды Гильдии Лидеров
		var liders;
		var hide_liders = false;
		all = document.querySelectorAll("td");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Лучшие отряды Гильдии Лидеров") === 0) {
				s = all[i];
				break;
			}
		}
		if (s) {
			logl = s.parentNode.nextSibling;
			logl.style.display = 'none';
			s.addEventListener('click', expandLogl);

			function expandLogl() {
				if (hide_liders) {
					logl.style.display = 'none';
				} else {
					logl.style.display = '';
				}
				hide_liders = !hide_liders;
			}
		}
		// Лучшие отряды Гильдии Лидеров
		var bestliders;
		var hide_bestliders = false;
		all = document.querySelectorAll("td");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Лучшие отряды Гильдии Лидеров") === 0) {
				s = all[i];
				break;
			}
		}
		if (s) {
			zash = s.parentNode.nextSibling;
			zash.style.display = 'none';
			s.addEventListener('click', expandVal);

			function expandVal() {
				if (hide_bestliders)
					zash.style.display = 'none';
				else
					zash.style.display = '';
				hide_bestliders = !hide_bestliders;
			}
		}
		// Подарки
		var podarki;
		var hide_podarki = false;
		all = document.querySelectorAll("td");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Подарки - ") === 0) {
				s = all[i];
				break;
			}
		}
		if (s) {
			zash = s.parentNode.nextSibling;
			zash.style.display = 'none';
			s.addEventListener('click', expandVal);

			function expandVal() {
				if (hide_podarki)
					zash.style.display = 'none';
				else
					zash.style.display = '';
				hide_podarki = !hide_podarki;
			}
		}
		// перенос инфы наверх
		var perinf;
		all = document.querySelectorAll("td");
		s = false;
		for (var i in all) {
			if (!all[i].innerText) continue;
			if (all[i].innerText.indexOf("Личная информация") === 0) {
				s = all[i];
				//return; //выкл
				break; //вкл
			}
		}
		if (s.parentNode != null && s.parentNode.parentNode != null && s.parentNode.parentNode.parentNode != null) {
			var table = s.parentNode.parentNode.parentNode;
			var main = table.parentNode;
			main.insertBefore(table, main.firstChild);
		}
	}

	// Инфа о клане
	if (document.location.pathname.includes('/clan_info.php')) {
		/*var clan_info_tr = document.createElement('tr');
		clan_info_tr.innerHTML = '<td width="100%" class="wb" align="left" style="border-top: none;"><b>Информация о клане</b></td>';
		clan_info_tr.style.cursor='pointer'
		document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(2)').after(clan_info_tr)
		clan_info_tr.addEventListener('click', expand_clan_info);
		var clan_info_show = true;

		var clan_info = document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(5)' && 'body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(4) > td' && 'body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(6) > td')
		var clan_info = document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(5)') ? document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(5)') : '';
		var clan_info1 = document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(7)') ? document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(7)') : '';
		var clan_info2 = document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(6)') ? document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(6)') : '';
		var clan_info3 = document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(1)') ? document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(1)') : '';
		var clan_info4 = document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(4)') ? document.querySelector('body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(4)') : '';

		expand_clan_info();
		function expand_clan_info() {
			if (clan_info_show) {
				clan_info ? clan_info.style.display = 'none' : '';
				clan_info1 ? clan_info1.style.display = 'none' : '';
				clan_info2 ? clan_info2.style.display = 'none' : '';
				clan_info3 ? clan_info3.style.display = 'none' : '';
				clan_info4 ? clan_info4.style.display = 'none' : '';
			} else {
				//clan_info.style.display ? clan_info.style.display = 'none' : '';
				//clan_info1.style.display ? clan_info1.style.display = 'none' : '';
				//clan_info2.style.display ? clan_info2.style.display = 'none' : '';
				clan_info3.style.display ? clan_info3.style.display = 'none' : '';
				clan_info4.style.display ? clan_info4.style.display = 'none' : '';
			}
			clan_info_show = !clan_info_show;
		}*/
		AllClanInfo = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(3) > td")
		AllClanInfo1 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(4)")
		AllClanInfo2 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr > td > table:nth-child(1) > tbody > tr:nth-child(5)")
		const NewClanButton = document.createElement("a");
		ClanId = window.location.href.split('=')[1];
		var ClanSearch = "a[href='clan_log.php?id=" + ClanId + '\']';
		const Protocol = document.querySelectorAll(ClanSearch)[0];

		NewClanButton.innerHTML = "<b>ПОКАЗАТЬ ПОЛНУЮ ИНФУ?</b>";
		//NewClanButton.style.fontSize = "x-large";
		//NewClanButton.style.display = 'flex';
		//NewClanButton.style.justifyContent = 'center';
		//NewClanButton.style.alignItems = 'center';
		//NewClanButton.style.backgroundColor = 'red';
		NewClanButton.style.cursor = 'pointer';
		NewClanButton.addEventListener('click', shClanInfo);
		Protocol.insertAdjacentElement('afterEnd', NewClanButton);
		Protocol.insertAdjacentHTML('afterEnd', '<td> | </td>');

		ClanInfoShow = true;
		shClanInfo();

		function shClanInfo() {
			if (ClanInfoShow && AllClanInfo1) {
				AllClanInfo.style.display = 'none';
				AllClanInfo1.style.display = 'none';
				if (AllClanInfo2 != null) {
					AllClanInfo2.style.display = 'none';
				}
				ClanInfoShow = false;
			} else if (ClanInfoShow == false && AllClanInfo1) {
				AllClanInfo.style.display = '';
				AllClanInfo1.style.display = '';
				if (AllClanInfo2 != null) {
					AllClanInfo2.style.display = '';
				}
				ClanInfoShow = true;
			} else if (ClanInfoShow && AllClanInfo1 == null) {
				AllClanInfo.style.display = 'none';
				ClanInfoShow = false;
			} else if (ClanInfoShow == false && AllClanInfo1 == null) {
				AllClanInfo.style.display = '';
				ClanInfoShow = true;
			}

		}

	}

	// страница Редактирования личной инфы
	if (document.location.pathname.includes('/pers_settings.php')) {
        //Настройки - <td class="wbwhite" width="35%">&nbsp;Графическое оформление меню</td>
		if (document.body.innerHTML.indexOf('Графическое оформление меню') == -1) {
			var OldInterface = 0;
		} else {
			var OldInterface = 2;
		}
		var Settings = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child(2) > td > b")
		Settings.style.cursor = 'pointer';
		Settings.addEventListener('click', shSettings);
		SettingsStatusVisible = true;
		StartPosition = 3;
		var Settings1 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition) + ")")
		var Settings2 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 1) + ")")
		var Settings3 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 2) + ")")
		var Settings4 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 3) + ")")
		var Settings5 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 4) + ")")
		var Settings6 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 5) + ")")
		if (OldInterface == 2) {
			Settings7 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + 1) + ")");
			Settings8 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + 2) + ")")
		}

		shSettings();

		function shSettings() {
			if (SettingsStatusVisible) {
				Settings1.style.display = 'none';
				Settings2.style.display = 'none';
				Settings3.style.display = 'none';
				Settings4.style.display = 'none';
				Settings5.style.display = 'none';
				Settings6.style.display = 'none';
				if (OldInterface == 2) {
					Settings7.style.display = 'none';
					Settings8.style.display = 'none';
				}
				SettingsStatusVisible = false;

			} else {
				Settings1.style.display = '';
				Settings2.style.display = '';
				Settings3.style.display = '';
				Settings4.style.display = '';
				Settings5.style.display = '';
				Settings6.style.display = '';
				if (OldInterface == 2) {
					Settings7.style.display = '';
					Settings8.style.display = '';
				}
				SettingsStatusVisible = true;
			}
		}

		//Настройки графики
		var SettingsGraphics = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 6) + ") > td > b")
		var SettingsGraphics1 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 7) + ")")
		var SettingsGraphics2 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 8) + ")")
		var SettingsGraphics3 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 9) + ")")
		SettingsGraphics.style.cursor = 'pointer';
		SettingsGraphics.addEventListener('click', shSettingsGraphics);
		SettingsGraphicsVisible = true;
		shSettingsGraphics();

		function shSettingsGraphics() {
			if (SettingsGraphicsVisible) {
				SettingsGraphics1.style.display = 'none';
				SettingsGraphics2.style.display = 'none';
				SettingsGraphics3.style.display = 'none';
				SettingsGraphicsVisible = false;

			} else {
				SettingsGraphics1.style.display = '';
				SettingsGraphics2.style.display = '';
				SettingsGraphics3.style.display = '';
				SettingsGraphicsVisible = true;
			}
		}

		//Настройки звука
		var SettingsSound = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 10) + ") > td > b");
		SettingsSound.style.cursor = 'pointer';
		SettingsSound.addEventListener('click', shSettingsSound);
		SettingsSoundVisible = true;
		var SettingsSound1 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 11) + ")");
		var SettingsSound2 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 12) + ")");
		var SettingsSound3 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 13) + ")");
		var SettingsSound4 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 14) + ")");
		shSettingsSound();

		function shSettingsSound() {
			if (SettingsSoundVisible) {
				SettingsSound1.style.display = 'none';
				SettingsSound2.style.display = 'none';
				SettingsSound3.style.display = 'none';
				SettingsSound4.style.display = 'none';
				SettingsSoundVisible = false;

			} else {
				SettingsSound1.style.display = '';
				SettingsSound2.style.display = '';
				SettingsSound3.style.display = '';
				SettingsSound4.style.display = '';
				SettingsSoundVisible = true;
			}
		}

		var SaySelf = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 15) + ") > td > b");
		SaySelf.style.cursor = 'pointer';
		SaySelf.addEventListener('click', shSaySelf);
		SaySelfVisible = true;
		var SaySelf1 = document.querySelector("body > center > table > tbody > tr > td > table > tbody > tr:nth-child" + '(' + (StartPosition + OldInterface + 16) + ")");
		shSaySelf();

		function shSaySelf() {
			if (SaySelfVisible) {
				SaySelf1.style.display = 'none';
				SaySelfVisible = false;

			} else {
				SaySelf1.style.display = '';
				SaySelfVisible = true;
			}
		}
	}
})();