<commit_before>/**
 *		===================
 *		blocks close & open
 *		===================
 */
document.addEventListener('DOMContentLoaded', blocksOpenClose);

function blocksOpenClose() {
	var blockTitleAll = document.querySelectorAll('.post-block.spoil>.block-title,.post-block.code>.block-title');

	if (!blockTitleAll[0]) return;

	for (var i = 0; i < blockTitleAll.length; i++) {
		var bt = blockTitleAll[i];
		var bb = bt.parentElement.querySelector('.block-body');
		if (bb.parentElement.classList.contains('code') && bb.scrollHeight <= bb.offsetHeight) {
			bb.parentElement.classList.remove('box');
		}
		bt.addEventListener('click', clickOnElement, false);
	}

	function clickOnElement(event) {
		var t = event.target;
		while (!t.classList.contains('post_body') || !t.classList.contains('msg-content') || t != document.body) {
			if (t.classList.contains('spoil')) {
				event.stopPropagation();
				toggler("close", "open", t);
				spoilCloseButton(t);
				return;
			} else if (t.classList.contains('code')) {
				event.stopPropagation();
				toggler("unbox", "box", t);
				return;
			}
			t = t.parentElement;
		}
	}

	function toggler(c, o, t) {
		if (t.classList.contains(c)) {
			t.classList.remove(c);
			t.classList.add(o);
			addImgesSrc(t);
		} else if (t.classList.contains(o)) {
			t.classList.remove(o);
			t.classList.add(c);
		}
	}
}

/**
 *		==================
 *		SPOIL CLOSE BUTTON
 *		==================
 */

function spoilCloseButton(t) {
	var el = t;
	while (!t.classList.contains('.post-body')) {
		if (t.classList.contains('spoil') && !t.querySelector('.spoil_close')) {
			if (t.querySelector('img[src]')) {
				var images = t.querySelectorAll('img[src]');
				images[images.length - 1].addEventListener("load",function(){
					spoilCloseButton(el);
				});
			}
			if (t.clientHeight > document.documentElement.clientHeight) {
				var bb = t.querySelector('.block-body');
				var btn = document.createElement('button');
				btn.innerHTML = 'Закрыть спойлер';
				btn.className = "spoil_close";
				btn.addEventListener('click', clickBtn);
				function clickBtn() {
					t.classList.remove('open');
					t.classList.add('close');
					t.scrollIntoView();
				}
				bb.appendChild(btn);
				return;
			}
		}
		t = t.parentElement;
	}
}

/**
 *		===============================
 *		HIDE AND SHOW IMAGES IN SPOILER
 *		===============================
 */

document.addEventListener('DOMContentLoaded', removeImgesSrc);

function removeImgesSrc() {
	if (document.body.classList.contains("noimages")) return;
	var postBlockSpoils = document.body.querySelectorAll('.post-block.spoil.close > .block-body');
	for (var i = 0; i < postBlockSpoils.length; i++) {
		var images = postBlockSpoils[i].querySelectorAll('img');
		for (var j = 0; j < images.length; j++) {
			var img = images[j];
			if (!img.hasAttribute('src') || img.dataset.imageSrc) continue;
			img.dataset.imageSrc = img.src;
			img.removeAttribute('src');
		}
	}
}

function addImgesSrc(target) {
	while (target != this) {
		if (target.classList.contains('spoil')) {
			var images = target.querySelectorAll('img');
			for (var i = 0; i < images.length; i++) {
				var img = images[i];
				if (img.hasAttribute('src') || !img.dataset.imageSrc) continue;
				img.src = img.dataset.imageSrc;
				img.removeAttribute('data-image-src');
			}
			return;
		}
		target = target.parentNode;
	}
}

/**
 *		========================
 *		add anchor link to spoil
 *		========================
 */

document.addEventListener('DOMContentLoaded', createAnchorSpoilerLink);

function createAnchorSpoilerLink() {
	if (document.body.id != 'topic' || document.body.querySelector('.block-title .anchor')) return;
	var postAll = document.querySelectorAll('.post_container');
	for (var i = 0; i < postAll.length; i++) {
		var postId = postAll[i].getAttribute('name').match(/\d+/);
		var spoilerAll = postAll[i].querySelectorAll('.post-block.spoil > .block-title');
		for (var j = 0; j < spoilerAll.length; j++) {
			if (spoilerAll[j].textContent.length == 0) spoilerAll[j].classList.add('empty');
			spoilerAll[j].insertAdjacentHTML("beforeEnd", '<a class="anchor" onclick="event.preventDefault();" href="http://4pda.ru/forum/index.php?act=findpost&pid=' + postId + '&anchor=Spoil-' + postId + '-' + (j + 1) + '" name="Spoil-' + postId + '-' + (j + 1) + '" title="Spoil-' + postId + '-' + (j + 1) + '"><span>#</span></a>');
		}
	}
}

/**
 *		===========
 *		scroll page
 *		===========
 */

function scrollToAnchor() {
    if (document.body.id != "topic") return;
	var anchor;
	if(window.FORPDA_POST){
	    anchor = document.querySelector('[name="' + window.FORPDA_POST.match(/[^#].*/) + '"]');
	}
	if (!anchor){
	    anchor = document.body;
	} else {
	    var p = anchor;
	    if (anchor.nodeName == 'A') {
    		while (!p.classList.contains('post_container')) {
    			if (p.classList.contains('spoil')) {
    				p.classList.remove('close');
    				p.classList.add('open');
    				addImgesSrc(p);
    			}
    			if (p.classList.contains('hat')) {
    				p.children[0].classList.remove('close');
    				p.children[0].classList.add('open');
    				p.children[1].removeAttribute('style');
    			}
    			p = p.parentNode;
    		}
    	}

    	// highlight "target post"
    	if (anchor.nodeName == 'DIV' && !anchor.nextElementSibling.classList.contains('active')) {
    		anchor.insertAdjacentHTML("beforeBegin", '<div class="target_post"></div>');
    		anchor.nextElementSibling.classList.add('active');
    	}
	}

	// jump to the anchor
	anchor.scrollIntoView();
	window.addEventListener('load', function() {
	    setTimeout(function(){
            anchor.scrollIntoView();
        }, 1000/30);
	});
}
document.addEventListener('DOMContentLoaded', scrollToAnchor);

function jumpToAnchorOnPage() {
	// in topic
	var snapAll = document.body.querySelectorAll('a[title="Перейти к сообщению"]');
	if (snapAll[0]) {
		for (var i = 0; i < snapAll.length; i++) {
			snapAll[i].addEventListener('click', onClickAnchor);
			function onClickAnchor(e) {
				var anchor = document.querySelector('[name="entry' + e.target.href.match(/findpost&pid=([\s\S]*)/)[1] + '"]');
				if (anchor) {
					e.preventDefault();
					anchor.scrollIntoView();
				}
			}
		}
	}
	// in news
	var commentAnchor = document.querySelector('a[href*="#comments"]');
	if (commentAnchor) {
		function jumpToNewsComment(e) {
			e.preventDefault();
			document.querySelector('#comments').scrollIntoView();
		}
		commentAnchor.addEventListener("click", jumpToNewsComment);
	}
}
document.addEventListener('DOMContentLoaded', jumpToAnchorOnPage);

window.addEventListener('load', scrollPageQMS);
function scrollPageQMS() {
	if (document.body.id == "qms"){
	    window.scrollTo(0, document.body.scrollHeight);
	}else if(document.body.id == "qms_more"){
	    var elements = document.getElementsByClassName("date");
	    if (elements.length > 7){
	        var el = elements[Math.max(elements.length % 7,7)];
            var x = 0;
            var y = 0;
            while (el != null) {
                x += el.offsetLeft;
                y += el.offsetTop;
                el = el.parent;
            }
            window.scrollTo(0, y);
        }
	}
}

/**
 *		=============
 *		selected text
 *		=============
 */

function getSelectedText() {
	var txt = '';
	if (window.getSelection) {
		txt = window.getSelection();
	} else if (document.getSelection) {
		txt = document.getSelection();
	} else if (document.selection) {
		txt = document.selection.createRange().text;
	} else return;
	return txt;
};

/**
 *		====================
 *		code lines numbering
 *		====================
 */

document.addEventListener('DOMContentLoaded', numberingCodeLinesFoo);

function numberingCodeLinesFoo() {
	var codeBlockAll = document.querySelectorAll('.post-block.code');<commit_msg>try-catch<commit_after>/**
 *		===================
 *		blocks close & open
 *		===================
 */
document.addEventListener('DOMContentLoaded', blocksOpenClose);

function blocksOpenClose() {
	var blockTitleAll = document.querySelectorAll('.post-block.spoil>.block-title,.post-block.code>.block-title');

	if (!blockTitleAll[0]) return;

	for (var i = 0; i < blockTitleAll.length; i++) {
		var bt = blockTitleAll[i];
		var bb = bt.parentElement.querySelector('.block-body');
		if (bb.parentElement.classList.contains('code') && bb.scrollHeight <= bb.offsetHeight) {
			bb.parentElement.classList.remove('box');
		}
		bt.addEventListener('click', clickOnElement, false);
	}

	function clickOnElement(event) {
		var t = event.target;
		while (!t.classList.contains('post_body') || !t.classList.contains('msg-content') || t != document.body) {
			if (t.classList.contains('spoil')) {
				event.stopPropagation();
				toggler("close", "open", t);
				spoilCloseButton(t);
				return;
			} else if (t.classList.contains('code')) {
				event.stopPropagation();
				toggler("unbox", "box", t);
				return;
			}
			t = t.parentElement;
		}
	}

	function toggler(c, o, t) {
		if (t.classList.contains(c)) {
			t.classList.remove(c);
			t.classList.add(o);
			addImgesSrc(t);
		} else if (t.classList.contains(o)) {
			t.classList.remove(o);
			t.classList.add(c);
		}
	}
}

/**
 *		==================
 *		SPOIL CLOSE BUTTON
 *		==================
 */

function spoilCloseButton(t) {
	var el = t;
	while (!t.classList.contains('.post-body')) {
		if (t.classList.contains('spoil') && !t.querySelector('.spoil_close')) {
			if (t.querySelector('img[src]')) {
				var images = t.querySelectorAll('img[src]');
				images[images.length - 1].addEventListener("load",function(){
					spoilCloseButton(el);
				});
			}
			if (t.clientHeight > document.documentElement.clientHeight) {
				var bb = t.querySelector('.block-body');
				var btn = document.createElement('button');
				btn.innerHTML = 'Закрыть спойлер';
				btn.className = "spoil_close";
				btn.addEventListener('click', clickBtn);
				function clickBtn() {
					t.classList.remove('open');
					t.classList.add('close');
					t.scrollIntoView();
				}
				bb.appendChild(btn);
				return;
			}
		}
		t = t.parentElement;
	}
}

/**
 *		===============================
 *		HIDE AND SHOW IMAGES IN SPOILER
 *		===============================
 */

document.addEventListener('DOMContentLoaded', removeImgesSrc);

function removeImgesSrc() {
	if (document.body.classList.contains("noimages")) return;
	var postBlockSpoils = document.body.querySelectorAll('.post-block.spoil.close > .block-body');
	for (var i = 0; i < postBlockSpoils.length; i++) {
		var images = postBlockSpoils[i].querySelectorAll('img');
		for (var j = 0; j < images.length; j++) {
			var img = images[j];
			if (!img.hasAttribute('src') || img.dataset.imageSrc) continue;
			img.dataset.imageSrc = img.src;
			img.removeAttribute('src');
		}
	}
}

function addImgesSrc(target) {
	while (target != this) {
		if (target.classList.contains('spoil')) {
			var images = target.querySelectorAll('img');
			for (var i = 0; i < images.length; i++) {
				var img = images[i];
				if (img.hasAttribute('src') || !img.dataset.imageSrc) continue;
				img.src = img.dataset.imageSrc;
				img.removeAttribute('data-image-src');
			}
			return;
		}
		target = target.parentNode;
	}
}

/**
 *		========================
 *		add anchor link to spoil
 *		========================
 */

document.addEventListener('DOMContentLoaded', createAnchorSpoilerLink);

function createAnchorSpoilerLink() {
	if (document.body.id != 'topic' || document.body.querySelector('.block-title .anchor')) return;
	var postAll = document.querySelectorAll('.post_container');
	for (var i = 0; i < postAll.length; i++) {
		var postId = postAll[i].getAttribute('name').match(/\d+/);
		var spoilerAll = postAll[i].querySelectorAll('.post-block.spoil > .block-title');
		for (var j = 0; j < spoilerAll.length; j++) {
			if (spoilerAll[j].textContent.length == 0) spoilerAll[j].classList.add('empty');
			spoilerAll[j].insertAdjacentHTML("beforeEnd", '<a class="anchor" onclick="event.preventDefault();" href="http://4pda.ru/forum/index.php?act=findpost&pid=' + postId + '&anchor=Spoil-' + postId + '-' + (j + 1) + '" name="Spoil-' + postId + '-' + (j + 1) + '" title="Spoil-' + postId + '-' + (j + 1) + '"><span>#</span></a>');
		}
	}
}

/**
 *		===========
 *		scroll page
 *		===========
 */

function scrollToAnchor() {
    if (document.body.id != "topic") return;
	var anchor;
	if(window.FORPDA_POST){
	    anchor = document.querySelector('[name="' + window.FORPDA_POST.match(/[^#].*/) + '"]');
	}
	if (!anchor){
	    anchor = document.body;
	} else {
	    var p = anchor;
	    if (anchor.nodeName == 'A') {
    		while (!p.classList.contains('post_container')) {
    			if (p.classList.contains('spoil')) {
    				p.classList.remove('close');
    				p.classList.add('open');
    				addImgesSrc(p);
    			}
    			if (p.classList.contains('hat')) {
    				p.children[0].classList.remove('close');
    				p.children[0].classList.add('open');
    				p.children[1].removeAttribute('style');
    			}
    			p = p.parentNode;
    		}
    	}

    	// highlight "target post"
    	if (anchor.nodeName == 'DIV' && !anchor.nextElementSibling.classList.contains('active')) {
    		anchor.insertAdjacentHTML("beforeBegin", '<div class="target_post"></div>');
    		anchor.nextElementSibling.classList.add('active');
    	}
	}

	// jump to the anchor
	anchor.scrollIntoView();
	window.addEventListener('load', function() {
	    setTimeout(function(){
            anchor.scrollIntoView();
        }, 1000/30);
	});
}
document.addEventListener('DOMContentLoaded', scrollToAnchor);

function jumpToAnchorOnPage() {
	// in topic
	var snapAll = document.body.querySelectorAll('a[title="Перейти к сообщению"]');
	if (snapAll[0]) {
		for (var i = 0; i < snapAll.length; i++) {
			snapAll[i].addEventListener('click', onClickAnchor);
			function onClickAnchor(e) {
				var anchor = document.querySelector('[name="entry' + e.target.href.match(/findpost&pid=([\s\S]*)/)[1] + '"]');
				if (anchor) {
					e.preventDefault();
					anchor.scrollIntoView();
				}
			}
		}
	}
	// in news
	var commentAnchor = document.querySelector('a[href*="#comments"]');
	if (commentAnchor) {
		function jumpToNewsComment(e) {
			e.preventDefault();
			document.querySelector('#comments').scrollIntoView();
		}
		commentAnchor.addEventListener("click", jumpToNewsComment);
	}
}
document.addEventListener('DOMContentLoaded', jumpToAnchorOnPage);

window.addEventListener('load', scrollPageQMS);
function scrollPageQMS() {
    try {
        if (document.body.id == "qms"){
            window.scrollTo(0, document.body.scrollHeight);
        }else if(document.body.id == "qms_more"){
            var elements = document.getElementsByClassName("date");
            if (elements.length > 7){
                var el = elements[Math.max(elements.length % 7,7)];
                var x = 0;
                var y = 0;
                while (el != null) {
                    x += el.offsetLeft;
                    y += el.offsetTop;
                    el = el.parent;
                }
                window.scrollTo(0, y);
            }
        }
	}catch(err){
	    console.error(err);
	}
}

/**
 *		=============
 *		selected text
 *		=============
 */

function getSelectedText() {
	var txt = '';
	if (window.getSelection) {
		txt = window.getSelection();
	} else if (document.getSelection) {
		txt = document.getSelection();
	} else if (document.selection) {
		txt = document.selection.createRange().text;
	} else return;
	return txt;
};

/**
 *		====================
 *		code lines numbering
 *		====================
 */

document.addEventListener('DOMContentLoaded', numberingCodeLinesFoo);

function numberingCodeLinesFoo() {
	var codeBlockAll = document.querySelectorAll('.post-block.code');
{'fraction_non_alphanumeric': 0.20510703169662708, 'fraction_numerical': 0.004065298862986724, 'mean_word_length': 3.4880273660205243, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '490704', 'n_tokens_mistral': 5704, 'n_tokens_neox': 5232, 'n_words': 880}