<commit_before>var pingTime = 10000;
var notificationIcon = '/favicon.ico';

$(function ()
{
	if ($('meta[property="og:image"]').length != 0)
		notificationIcon = $('meta[property="og:image"]').attr('content');

	$.get(notificationIcon).fail(function() { 
		notificationIcon = smf_images_url + '/blank.png';
	})
});

var updateAlerts = function ()
{
	var unreadAlerts;

	// Prevent multiple notifications across browsers
	if (typeof localStorage != 'undefined')
	{
		unreadAlerts = localStorage.getItem('alertsCounter');

		if (unreadAlerts != parseInt(unreadAlerts))
			return true;

		if ($('#alerts_menu_top > .amt:first').is(':visible'))
			$('#alerts_menu_top > .amt:first').text(unreadAlerts);
		else if (!$('#alerts_menu_top > .amt:first').is(':visible') && unreadAlerts != 0)
			$('#alerts_menu_top').append(' <span class="amt">' + unreadAlerts + '</span>');

		if (localStorage.getItem('alertsPoll') != null && (+(new Date()) - localStorage.getItem('alertsPoll')) < pingTime)
		{
			setTimeout(updateAlerts, 1000);
			return true;
		}
		localStorage.setItem('alertsPoll', +(new Date()));
	}
	else
		unreadAlerts = $('#alerts_menu_top > .amt:first').text() ? $('#alerts_menu_top > .amt:first').text() : 0;

	unreadAlerts = parseInt(unreadAlerts);

	$.get(smf_scripturl + '?action=profile;area=alerts_popup;counter=' + unreadAlerts + ';u=' + smf_member_id, function (data)
	{
		var alerts = $(data).find('.unread_notify');
		if (alerts.length == 0)
			return true;

		unreadAlerts += alerts.length;

		if (unreadAlerts != parseInt(unreadAlerts))
			return true;

		if (typeof localStorage != 'undefined')
			localStorage.setItem('alertsCounter', unreadAlerts);

		if ($('#alerts_menu_top > .amt:first').is(':visible'))
			$('#alerts_menu_top > .amt:first').text(unreadAlerts);
		else if (!$('#alerts_menu_top > .amt:first').is(':visible') && unreadAlerts != 0)
			$('#alerts_menu_top').append('<span class="amt">' + unreadAlerts + '</span>');

		$.each(alerts, function(index, item)
		{
			var notification = notify.createNotification(new_alert_title, {
				body: $(item).find('div.details:first span.alert_text').text(),
				icon: notificationIcon
			});

			notification.click(function()
			{
				window.focus();
				if (!$('#alerts_menu').is(':visible'))
					$('#alerts_menu_top').click();
			});

			if (alert_timeout > 0)
				setTimeout(function()
				{
					notification.close();
				}, alert_timeout);
		});

		var user_menus = new smc_PopupMenu();
		user_menus.add("alerts", smf_scripturl + "?action=profile;area=alerts_popup;u=" + smf_member_id);
	});

	setTimeout(updateAlerts, pingTime);<commit_msg>Close the desktop notification after opening it<commit_after>var pingTime = 10000;
var notificationIcon = '/favicon.ico';

$(function ()
{
	if ($('meta[property="og:image"]').length != 0)
		notificationIcon = $('meta[property="og:image"]').attr('content');

	$.get(notificationIcon).fail(function() { 
		notificationIcon = smf_images_url + '/blank.png';
	})
});

var updateAlerts = function ()
{
	var unreadAlerts;

	// Prevent multiple notifications across browsers
	if (typeof localStorage != 'undefined')
	{
		unreadAlerts = localStorage.getItem('alertsCounter');

		if (unreadAlerts != parseInt(unreadAlerts))
			return true;

		if ($('#alerts_menu_top > .amt:first').is(':visible'))
			$('#alerts_menu_top > .amt:first').text(unreadAlerts);
		else if (!$('#alerts_menu_top > .amt:first').is(':visible') && unreadAlerts != 0)
			$('#alerts_menu_top').append(' <span class="amt">' + unreadAlerts + '</span>');

		if (localStorage.getItem('alertsPoll') != null && (+(new Date()) - localStorage.getItem('alertsPoll')) < pingTime)
		{
			setTimeout(updateAlerts, 1000);
			return true;
		}
		localStorage.setItem('alertsPoll', +(new Date()));
	}
	else
		unreadAlerts = $('#alerts_menu_top > .amt:first').text() ? $('#alerts_menu_top > .amt:first').text() : 0;

	unreadAlerts = parseInt(unreadAlerts);

	$.get(smf_scripturl + '?action=profile;area=alerts_popup;counter=' + unreadAlerts + ';u=' + smf_member_id, function (data)
	{
		var alerts = $(data).find('.unread_notify');
		if (alerts.length == 0)
			return true;

		unreadAlerts += alerts.length;

		if (unreadAlerts != parseInt(unreadAlerts))
			return true;

		if (typeof localStorage != 'undefined')
			localStorage.setItem('alertsCounter', unreadAlerts);

		if ($('#alerts_menu_top > .amt:first').is(':visible'))
			$('#alerts_menu_top > .amt:first').text(unreadAlerts);
		else if (!$('#alerts_menu_top > .amt:first').is(':visible') && unreadAlerts != 0)
			$('#alerts_menu_top').append('<span class="amt">' + unreadAlerts + '</span>');

		$.each(alerts, function(index, item)
		{
			var notification = notify.createNotification(new_alert_title, {
				body: $(item).find('div.details:first span.alert_text').text(),
				icon: notificationIcon
			});

			notification.click(function()
			{
				window.focus();
				if (!$('#alerts_menu').is(':visible'))
					$('#alerts_menu_top').click();

				this.close();
			});

			if (alert_timeout > 0)
				setTimeout(function()
				{
					notification.close();
				}, alert_timeout);
		});

		var user_menus = new smc_PopupMenu();
		user_menus.add("alerts", smf_scripturl + "?action=profile;area=alerts_popup;u=" + smf_member_id);
	});

	setTimeout(updateAlerts, pingTime);
{'fraction_non_alphanumeric': 0.19285309132161088, 'fraction_numerical': 0.005672149744753261, 'mean_word_length': 4.943820224719101, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, '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': '905284', 'n_tokens_mistral': 2045, 'n_tokens_neox': 1838, 'n_words': 308}