<commit_before>var intervalId = -1;

$(document).ready(function() {
	// From https://gist.github.com/alanhamlett/6316427
	$.ajaxSetup({
		beforeSend: function(xhr, settings) {
			if (settings.type == 'POST' || settings.type == 'PUT' || settings.type == 'DELETE' || settings.type == 'PATCH') {
				xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
			}
		}
	});

	function updateTimers() {
		$.ajax({
			url: '/status/',
			method: 'GET',
			data: {
				'key': webKey,
			},
			contentType: 'application/json',
			success: function(data) {
				data = JSON.parse(data);

				for (i in data) {
					var goal = data[i];
					var goalElement = $(".goal[data-id=" + goal.id + "]");

					if (goalElement.find(".button.stop").length > 0) {
						goalElement.find(".timer .num").html(goal.current_elapsed);
						goalElement.find(".timer .seconds").html(goal.current_elapsed_in_seconds);
						goalElement.find(".info .current").html(goal.current_amount);
						goalElement.find(".percentage .bar").css("width", goal.current_percentage + "%");

						if (goal.current_amount >= parseFloat(goalElement.find(".info .target").html())) {
							goalElement.find(".percentage .bar").addClass("over");
						}
					}
				}
			},
			error: function(data) {
				console.log("error", data);
			},
		});
	}

	function checkTimers() {
		if (intervalId == -1) {
			intervalId = setInterval(updateTimers, 1000);
		}
	}

	if ($(".goal .button.stop").length > 0) {
		checkTimers();

		// Update the favicon
		updateFavicon("timer");
	}

	function updateFavicon(type) {
		var dataHref = "data-" + type + "-href";

		var oldIco = $("#favicon-ico");
		var oldPng = $("#favicon-png");

		var newIco = "<link id='favicon-ico' rel='shortcut icon' href='" + oldIco.attr(dataHref) + "' data-original-href='" + oldIco.attr("data-original-href") + "' data-timer-href='" + oldIco.attr("data-timer-href") + "' />";
		var newPng = "<link id='favicon-png' rel='shortcut icon' href='" + oldPng.attr(dataHref) + "' data-original-href='" + oldPng.attr("data-original-href") + "' data-timer-href='" + oldPng.attr("data-timer-href") + "' />";

		oldIco.remove();
		oldPng.remove();

		$("head").append(newIco);
		$("head").append(newPng);
	}

	function toggleButtonClass(button, data) {
		if (button.hasClass("start")) {
			// Turn into a Stop button
			button.addClass("stop").removeClass("start");
			button.find(".label").html("Stop");

			// Show the timer
			button.find(".timer").removeClass("hidden");

			// Set it running and remove the stale class if it's there
			button.parents(".goal").addClass("running").removeClass("stale");

			// Update the favicon
			updateFavicon("timer");

			checkTimers();
		} else if (button.hasClass("stop")) {
			// Turn into a Start button
			button.addClass("start").removeClass("stop");
			button.find(".label").html("Start");

			// Hide the timer
			button.find(".timer").addClass("hidden");

			// Stop it running
			button.parents(".goal").removeClass("running");

			// Stop pinging the status web service if there aren't any more active timers
			if ($(".goal .button.stop").length == 0) {
				clearInterval(intervalId);
				intervalId = -1;

				// Change the favicon back
				updateFavicon("original");
			}
		}
	}

	// Start/stop buttons
	$(".button.action").on("click touchstart", function() {
		// Get the id of the goal we want
		var goalId = $(this).parents(".goal").attr("data-id");
		var button = $(this);

		if (goalId != '') {
			// Send in the timer request
			// It's GET so we can use it in Launch Center Pro, Drafts, etc.
			$.ajax({
				url: '/' + goalId + '/timer/',<commit_msg>Hide completed goals<commit_after>var intervalId = -1;

$(document).ready(function() {
	// From https://gist.github.com/alanhamlett/6316427
	$.ajaxSetup({
		beforeSend: function(xhr, settings) {
			if (settings.type == 'POST' || settings.type == 'PUT' || settings.type == 'DELETE' || settings.type == 'PATCH') {
				xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
			}
		}
	});

	function updateTimers() {
		$.ajax({
			url: '/status/',
			method: 'GET',
			data: {
				'key': webKey,
			},
			contentType: 'application/json',
			success: function(data) {
				data = JSON.parse(data);

				for (i in data) {
					var goal = data[i];
					var goalElement = $(".goal[data-id=" + goal.id + "]");

					if (goalElement.find(".button.stop").length > 0) {
						goalElement.find(".timer .num").html(goal.current_elapsed);
						goalElement.find(".timer .seconds").html(goal.current_elapsed_in_seconds);
						goalElement.find(".info .current").html(goal.current_amount);
						goalElement.find(".percentage .bar").css("width", goal.current_percentage + "%");

						if (goal.current_amount >= parseFloat(goalElement.find(".info .target").html())) {
							goalElement.find(".percentage .bar").addClass("over");
						}
					}
				}
			},
			error: function(data) {
				console.log("error", data);
			},
		});
	}

	function checkTimers() {
		if (intervalId == -1) {
			intervalId = setInterval(updateTimers, 1000);
		}
	}

	if ($(".goal .button.stop").length > 0) {
		checkTimers();

		// Update the favicon
		updateFavicon("timer");
	}

	function updateFavicon(type) {
		var dataHref = "data-" + type + "-href";

		var oldIco = $("#favicon-ico");
		var oldPng = $("#favicon-png");

		var newIco = "<link id='favicon-ico' rel='shortcut icon' href='" + oldIco.attr(dataHref) + "' data-original-href='" + oldIco.attr("data-original-href") + "' data-timer-href='" + oldIco.attr("data-timer-href") + "' />";
		var newPng = "<link id='favicon-png' rel='shortcut icon' href='" + oldPng.attr(dataHref) + "' data-original-href='" + oldPng.attr("data-original-href") + "' data-timer-href='" + oldPng.attr("data-timer-href") + "' />";

		oldIco.remove();
		oldPng.remove();

		$("head").append(newIco);
		$("head").append(newPng);
	}

	function toggleButtonClass(button, data) {
		if (button.hasClass("start")) {
			// Turn into a Stop button
			button.addClass("stop").removeClass("start");
			button.find(".label").html("Stop");

			// Show the timer
			button.find(".timer").removeClass("hidden");

			// Set it running and remove the stale class if it's there
			button.parents(".goal").addClass("running").removeClass("stale");

			// Update the favicon
			updateFavicon("timer");

			checkTimers();
		} else if (button.hasClass("stop")) {
			// Turn into a Start button
			button.addClass("start").removeClass("stop");
			button.find(".label").html("Start");

			// Hide the timer
			button.find(".timer").addClass("hidden");

			// Stop it running
			button.parents(".goal").removeClass("running");

			// Stop pinging the status web service if there aren't any more active timers
			if ($(".goal .button.stop").length == 0) {
				clearInterval(intervalId);
				intervalId = -1;

				// Change the favicon back
				updateFavicon("original");
			}

			// If it was complete, hide it
			if (button.parents(".goal").find(".percentage .bar").hasClass("over")) {
				button.parents(".goal").slideUp(150);
			}
		}
	}

	// Start/stop buttons
	$(".button.action").on("click touchstart", function() {
		// Get the id of the goal we want
		var goalId = $(this).parents(".goal").attr("data-id");
		var button = $(this);

		if (goalId != '') {
			// Send in the timer request
			// It's GET so we can use it in Launch Center Pro, Drafts, etc.
			$.ajax({
				url: '/' + goalId + '/timer/',
{'fraction_non_alphanumeric': 0.1991347843720427, 'fraction_numerical': 0.005002027849128025, 'mean_word_length': 3.3646017699115043, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '7457952', 'n_tokens_mistral': 2922, 'n_tokens_neox': 2431, 'n_words': 505}