<commit_before>function $(query) {return document.querySelector(query)}

function localStorageGet(key) {
	try {
		return window.localStorage[key]
	}
	catch(e) {}
}

function localStorageSet(key, val) {
	try {
		window.localStorage[key] = val
	}
	catch(e) {}
}


var ws
var myNick = localStorageGet('my-nick')
var myChannel = window.location.search.replace(/^\?/, '')
var lastSent = [""]
var lastSentPos = 0
var log = ""


// Ping server every 50 seconds to retain WebSocket connection
window.setInterval(function() {
	send({cmd: 'ping'})
}, 50000)


function join(channel) {
	if (document.domain == 'hack.chat') {
		// For https://hack.chat/
		ws = new WebSocket('wss://hack.chat/chat-ws')
	}
	else {
		// for local installs
		if (document.location.protocol == 'https:') {
			ws = new WebSocket('wss://' + document.domain + ':6060')
		}
		else {
			ws = new WebSocket('ws://' + document.domain + ':6060')
		}
	}

	var wasConnected = false

	ws.onopen = function() {
		if (!wasConnected) {
			if (location.hash) {
				myNick = location.hash.substr(1)
			}
			else {
				myNick = prompt('Nickname:', myNick)
			}
		}
		if (myNick) {
			localStorageSet('my-nick', myNick)
			send({cmd: 'join', channel: channel, nick: myNick})
		}
		wasConnected = true
	}

	ws.onclose = function() {
		if (wasConnected) {
			pushMessage({nick: '!', text: "Server disconnected. Attempting to reconnect..."})
		}
		window.setTimeout(function() {
			join(channel)
		}, 2000)
	}

	ws.onmessage = function(message) {
		var args = JSON.parse(message.data)
		var cmd = args.cmd
		var command = COMMANDS[cmd]
		command.call(null, args)
	}
}


var COMMANDS = {
	chat: function(args) {
		if (ignoredUsers.indexOf(args.nick) >= 0) {
			return
		}
		pushMessage(args)
		if ($('#notifications-enabled').checked && args.nick != myNick) {
			showNotification(args.nick + ': ' + args.text)
		}
	},
	info: function(args) {
		args.nick = '*'
		pushMessage(args)
		if ($('#notifications-enabled').checked) {
			showNotification(args.nick + ': ' + args.text)
		}
	},
	warn: function(args) {
		args.nick = '!'
		pushMessage(args)
		if ($('#notifications-enabled').checked) {
			showNotification(args.nick + ': ' + args.text)
		}
	},<commit_msg>Show notifications only when window not focused.<commit_after>function $(query) {return document.querySelector(query)}

function localStorageGet(key) {
	try {
		return window.localStorage[key]
	}
	catch(e) {}
}

function localStorageSet(key, val) {
	try {
		window.localStorage[key] = val
	}
	catch(e) {}
}


var ws
var myNick = localStorageGet('my-nick')
var myChannel = window.location.search.replace(/^\?/, '')
var lastSent = [""]
var lastSentPos = 0
var log = ""


// Ping server every 50 seconds to retain WebSocket connection
window.setInterval(function() {
	send({cmd: 'ping'})
}, 50000)


function join(channel) {
	if (document.domain == 'hack.chat') {
		// For https://hack.chat/
		ws = new WebSocket('wss://hack.chat/chat-ws')
	}
	else {
		// for local installs
		if (document.location.protocol == 'https:') {
			ws = new WebSocket('wss://' + document.domain + ':6060')
		}
		else {
			ws = new WebSocket('ws://' + document.domain + ':6060')
		}
	}

	var wasConnected = false

	ws.onopen = function() {
		if (!wasConnected) {
			if (location.hash) {
				myNick = location.hash.substr(1)
			}
			else {
				myNick = prompt('Nickname:', myNick)
			}
		}
		if (myNick) {
			localStorageSet('my-nick', myNick)
			send({cmd: 'join', channel: channel, nick: myNick})
		}
		wasConnected = true
	}

	ws.onclose = function() {
		if (wasConnected) {
			pushMessage({nick: '!', text: "Server disconnected. Attempting to reconnect..."})
		}
		window.setTimeout(function() {
			join(channel)
		}, 2000)
	}

	ws.onmessage = function(message) {
		var args = JSON.parse(message.data)
		var cmd = args.cmd
		var command = COMMANDS[cmd]
		command.call(null, args)
	}
}


var COMMANDS = {
	chat: function(args) {
		if (ignoredUsers.indexOf(args.nick) >= 0) {
			return
		}
		pushMessage(args)
		if (!windowActive && $('#notifications-enabled').checked && args.nick != myNick) {
			showNotification(args.nick + ': ' + args.text)
		}
	},
	info: function(args) {
		args.nick = '*'
		pushMessage(args)
		if (!windowActive && $('#notifications-enabled').checked) {
			showNotification(args.nick + ': ' + args.text)
		}
	},
	warn: function(args) {
		args.nick = '!'
		pushMessage(args)
		if (!windowActive && $('#notifications-enabled').checked) {
			showNotification(args.nick + ': ' + args.text)
		}
	},
{'fraction_non_alphanumeric': 0.17356475300400534, 'fraction_numerical': 0.009790832220738763, 'mean_word_length': 3.5130522088353415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1726413', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1587, 'n_words': 325}