<commit_before>/* jslint browser: true */
var hostname = location.hostname.split('.').slice(1).join('.');
var createDivs = function ( data ) {
	var body = document.querySelector( '.counter');
	var queues = [ 
		[ 'best' ],
		[ 'good', 'decent', 'music' ],
		[ 'pending' ],
		[ 'bad' ],
		['trash' ]
	];

	var prog = document.createElement( 'progress' );
	prog.className = 'progress';
	prog.id = 'progress';
	body.appendChild(prog);


	var delta = document.createElement( 'div' );
	delta.className = 'delta';
	delta.id = 'delta';
	delta.innerHTML = 'Δ0';
	body.appendChild(delta);

	for ( var i = 0; i < queues.length; i++  ) {
		for ( var j = 0; j < queues[i].length; j++ ) {
			var queue = queues[i][j];
			var div = document.createElement( 'div' );
			if ( queue === 'total' ) {
				continue;
			}

			div.className = 'queue ' + queue;
			div.id = queue;

			body.appendChild( div );

			if ( j < queues[i].length - 1) {
				var sep = document.createElement( 'span' );
				sep.class = 'sep';
				sep.innerHTML = '&#x21c6'; //'&#x2194;';
				body.appendChild( sep );
			}

			if ( queue === 'trash' ) {
				continue;
			}
		}
		var span = document.createElement( 'span' );
		span.className = 'sep';
		if ( i === queue.length ) {
			span.innerHTML = '&#x2193;'; // downwards
		} else if ( i === queue.length - 1) {
			continue;
		} else if ( i === 0 ) {
			span.innerHTML = '&#x2191;'; // upwards
		} else {
			span.innerHTML = '&#x21f5'; //'&#x2195;'; //  updown
		}
		body.appendChild( span );
	}
};
var updateCounts = function ( data ) {
	var div;
	var total = 0 - data.counts.pending - data.counts.total;
	data.counts.good = data.counts.held;
	delete data.counts.held; // deletes property from object

	for ( var queue in data.counts ) {
		if ( data.counts.hasOwnProperty( queue ) ) {
			total += data.counts[queue];
			div = document.getElementById( queue );
			if ( !div ) { continue; }
			var text = data.counts[queue] + ' ' + queue;
			div.innerHTML = '<a href="//' + queue + '.' + hostname + '">' + text + '</a>';
			var size = 0.5 * Math.sqrt(data.counts[queue]) + 'em';
			div.style.height = size;
			div.style.width = size;
			div.style['line-height'] = size;
		}
	}

	var prog = document.getElementById( 'progress' );
	prog.max = data.counts.total;
	prog.value = total;


	div = document.getElementById( 'delta' );
	div.innerHTML = 'Δ' + data.delta + ' ' + Math.round( 100 * total / data.counts.total ) + '%';
	if ( data.delta < 0 ) {
		div.className = 'delta negative';
	} else if ( data.delta === 0 ) {
		div.className = 'delta zero';
	} else {
		div.className = 'delta';
	}
	setTimeout(poll, 3000);
};

var getJSON = function(url, callback) {
	// http://stackoverflow.com/a/35970894
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType = 'json';
    xhr.onload = function() {
      var status = xhr.status;
      if (status === 200) {
        callback(null, xhr.response);
      } else {
        callback(status);
      }
    };
    xhr.send();
};


function poll() {
	getJSON('//api.' + hostname + '/stats.json', function ( e, r ) {
		updateCounts( r );
	} );
}

window.onload = function () {
	getJSON('//api.' + hostname + '/stats.json', function ( e, r ) {
		createDivs( r );
		updateCounts( r );
	} );
};<commit_msg>Only poll for changes whilst visible<commit_after>/* jslint browser: true */
var hostname = location.hostname.split('.').slice(1).join('.');
var createDivs = function ( data ) {
	var body = document.querySelector( '.counter');
	var queues = [ 
		[ 'best' ],
		[ 'good', 'decent', 'music' ],
		[ 'pending' ],
		[ 'bad' ],
		['trash' ]
	];

	var prog = document.createElement( 'progress' );
	prog.className = 'progress';
	prog.id = 'progress';
	body.appendChild(prog);


	var delta = document.createElement( 'div' );
	delta.className = 'delta';
	delta.id = 'delta';
	delta.innerHTML = 'Δ0';
	body.appendChild(delta);

	for ( var i = 0; i < queues.length; i++  ) {
		for ( var j = 0; j < queues[i].length; j++ ) {
			var queue = queues[i][j];
			var div = document.createElement( 'div' );
			if ( queue === 'total' ) {
				continue;
			}

			div.className = 'queue ' + queue;
			div.id = queue;

			body.appendChild( div );

			if ( j < queues[i].length - 1) {
				var sep = document.createElement( 'span' );
				sep.class = 'sep';
				sep.innerHTML = '&#x21c6'; //'&#x2194;';
				body.appendChild( sep );
			}

			if ( queue === 'trash' ) {
				continue;
			}
		}
		var span = document.createElement( 'span' );
		span.className = 'sep';
		if ( i === queue.length ) {
			span.innerHTML = '&#x2193;'; // downwards
		} else if ( i === queue.length - 1) {
			continue;
		} else if ( i === 0 ) {
			span.innerHTML = '&#x2191;'; // upwards
		} else {
			span.innerHTML = '&#x21f5'; //'&#x2195;'; //  updown
		}
		body.appendChild( span );
	}
};
var updateCounts = function ( data ) {
	var div;
	var total = 0 - data.counts.pending - data.counts.total;
	data.counts.good = data.counts.held;
	delete data.counts.held; // deletes property from object

	for ( var queue in data.counts ) {
		if ( data.counts.hasOwnProperty( queue ) ) {
			total += data.counts[queue];
			div = document.getElementById( queue );
			if ( !div ) { continue; }
			var text = data.counts[queue] + ' ' + queue;
			div.innerHTML = '<a href="//' + queue + '.' + hostname + '">' + text + '</a>';
			var size = 0.5 * Math.sqrt(data.counts[queue]) + 'em';
			div.style.height = size;
			div.style.width = size;
			div.style['line-height'] = size;
		}
	}

	var prog = document.getElementById( 'progress' );
	prog.max = data.counts.total;
	prog.value = total;


	div = document.getElementById( 'delta' );
	div.innerHTML = 'Δ' + data.delta + ' ' + Math.round( 100 * total / data.counts.total ) + '%';
	if ( data.delta < 0 ) {
		div.className = 'delta negative';
	} else if ( data.delta === 0 ) {
		div.className = 'delta zero';
	} else {
		div.className = 'delta';
	}
	setTimeout(poll, 3000);
};

var getJSON = function(url, callback) {
	// http://stackoverflow.com/a/35970894
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType = 'json';
    xhr.onload = function() {
      var status = xhr.status;
      if (status === 200) {
        callback(null, xhr.response);
      } else {
        callback(status);
      }
    };
    xhr.send();
};


function poll() {
	console.log( document.hidden, "DOCHID" );
	if ( document.hidden === true ) {
		// pass
	} else {
		getJSON('//api.' + hostname + '/stats.json', function ( e, r ) {
			updateCounts( r );
		} );
	}
}

window.onload = function () {
	getJSON('//api.' + hostname + '/stats.json', function ( e, r ) {
		createDivs( r );
		updateCounts( r );
	} );
};

document.addEventListener( 'visibilitychange', poll, false );
{'fraction_non_alphanumeric': 0.19275319275319275, 'fraction_numerical': 0.015444015444015444, 'mean_word_length': 2.7965050732807217, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, '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': '1150147', 'n_tokens_mistral': 2694, 'n_tokens_neox': 2404, 'n_words': 555}