<commit_before>/*
 * auto-reload.js
 * https://github.com/savetheinternet/Tinyboard/blob/master/js/auto-reload.js
 *
 * Brings AJAX to Tinyboard.
 *
 * Released under the MIT license
 * Copyright (c) 2012 <NAME> <<EMAIL>>
 *
 * Usage:
 *   $config['additional_javascript'][] = 'js/jquery.min.js';
 *   $config['additional_javascript'][] = 'js/auto-reload.js';
 *
 */

$(document).ready(function(){
	if($('div.banner').length == 0)
		return; // not index
		
	if($(".post.op").size() != 1)
	return; //not thread page
	
	var poll_interval;

	var end_of_page = false;
	
	var poll = function() {
		$.ajax({
			url: document.location,
			success: function(data) {
				$(data).find('div.post.reply').each(function() {
					var id = $(this).attr('id');
					if($('#' + id).length == 0) {
						$(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
						$(document).trigger('new_post', this);
					}
				});
			}
		});
		
		clearTimeout(poll_interval);
		poll_interval = setTimeout(poll, end_of_page ? 3000 : 10000);
	};
	
	$(window).scroll(function() {
		if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) {
			end_of_page = false;
			return;
		}
		
		clearTimeout(poll_interval);
		poll_interval = setTimeout(poll, 100);
		end_of_page = true;<commit_msg>auto-reload.js: add a number indicating new posts in the tab title<commit_after>/*
 * auto-reload.js
 * https://github.com/savetheinternet/Tinyboard/blob/master/js/auto-reload.js
 *
 * Brings AJAX to Tinyboard.
 *
 * Released under the MIT license
 * Copyright (c) 2012 <NAME> <<EMAIL>>
 *
 * Usage:
 *   $config['additional_javascript'][] = 'js/jquery.min.js';
 *   $config['additional_javascript'][] = 'js/auto-reload.js';
 *
 */

$(document).ready(function(){
	if($('div.banner').length == 0)
		return; // not index
		
	if($(".post.op").size() != 1)
	return; //not thread page
	
	var poll_interval;

	var end_of_page = false;

	var orig_title = document.title;
        var new_posts = 0;
	var first_new_post = null;
	var update_title = function() {
		document.title = (new_posts ? "("+new_posts+") " : "") + orig_title;
	};

	var window_active = true;
	$(window).focus(function() {
		window_active = true;
		recheck_activated();
	});
	$(window).blur(function() {
		window_active = false;
	});
	
	var recheck_activated = function() {
		if (new_posts && window_active &&
			$(window).scrollTop() + $(window).height() >=
			$(first_new_post).position().top) {

			new_posts = 0;
		}
		update_title();
	};

	var poll = function() {
		$.ajax({
			url: document.location,
			success: function(data) {
				$(data).find('div.post.reply').each(function() {
					var id = $(this).attr('id');
					if($('#' + id).length == 0) {
						if (!new_posts) {
							first_new_post = this;
						}
						$(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
						new_posts++;
						$(document).trigger('new_post', this);
						recheck_activated();
					}
				});
			}
		});
		
		clearTimeout(poll_interval);
		poll_interval = setTimeout(poll, end_of_page ? 3000 : 10000);
	};
	
	$(window).scroll(function() {
		recheck_activated();

		if($(this).scrollTop() + $(this).height() <
			$('div.post:last').position().top + $('div.post:last').height()) {
			end_of_page = false;
			return;
		}
		
		clearTimeout(poll_interval);
		poll_interval = setTimeout(poll, 100);
		end_of_page = true;
{'fraction_non_alphanumeric': 0.20181339572974555, 'fraction_numerical': 0.011699327288680901, 'mean_word_length': 3.541832669322709, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 2, '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': '4495936', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1175, 'n_words': 210}