<commit_before>import * as url from './url.js';

export const HISTORY_MENU = 0,
	HISTORY_GAME = 1;

export function getConnectionIds() {
	let res = location.hash.match(new RegExp('^#srv=([' + url.escapedUrlSafeChars + ']+)(?:&lobby=([' + url.escapedUrlSafeChars + ']+))?'));
	if (res === null) {
		return {
			serverId: null,
			lobbyId: null
		};
	} else {
		let [, serverId, lobbyId] = res;
		serverId = serverId === undefined ? null : url.decodeUint(serverId);
		lobbyId = lobbyId === undefined ? null : url.decodeUint(lobbyId);
		return {
			serverId,
			lobbyId
		};
	}
}

let navHandler;

export function push(serverId, lobbyId) {
	if (!serverId && !lobbyId) {
		history.pushState(HISTORY_MENU, '', location.pathname);
	} else if (lobbyId) { //assumes serverId is defined too
		history.pushState(HISTORY_GAME, '', location.pathname + '#srv=' + url.encodeUint(serverId) + '&lobby=' + url.encodeUint(lobbyId));
	} else {
		history.pushState(HISTORY_GAME, '', location.pathname + '#srv=' + url.encodeUint(serverId));
	}
	navHandler(history.state);
}
export function bindHistoryNavigation(handler) {
	navHandler = handler;
	window.addEventListener('popstate', () => {
		navHandler(history.state || HISTORY_MENU);
	});<commit_msg>Fix crash<commit_after>import * as url from './url.js';

export const HISTORY_MENU = 0,
	HISTORY_GAME = 1;

export function getConnectionIds() {
	let res = location.hash.match(new RegExp('^#srv=([' + url.escapedUrlSafeChars + ']+)(?:&lobby=([' + url.escapedUrlSafeChars + ']+))?'));
	if (res === null) {
		return {
			serverId: null,
			lobbyId: null
		};
	} else {
		let [, serverId, lobbyId] = res;
		serverId = serverId === undefined ? null : url.decodeUint(serverId);
		lobbyId = lobbyId === undefined ? null : url.decodeUint(lobbyId);
		return {
			serverId,
			lobbyId
		};
	}
}

let navHandler;

export function push(serverId, lobbyId) {
	if (serverId === undefined && lobbyId === undefined) {
		history.pushState(HISTORY_MENU, '', location.pathname);
	} else if (lobbyId === undefined) { //assumes serverId is defined too
		history.pushState(HISTORY_GAME, '', location.pathname + '#srv=' + url.encodeUint(serverId) + '&lobby=' + url.encodeUint(lobbyId));
	} else {
		history.pushState(HISTORY_GAME, '', location.pathname + '#srv=' + url.encodeUint(serverId));
	}
	navHandler(history.state);
}
export function bindHistoryNavigation(handler) {
	navHandler = handler;
	window.addEventListener('popstate', () => {
		navHandler(history.state || HISTORY_MENU);
	});
{'fraction_non_alphanumeric': 0.16853482786228982, 'fraction_numerical': 0.0016012810248198558, 'mean_word_length': 4.731651376146789, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4474304', 'n_tokens_mistral': 936, 'n_tokens_neox': 877, 'n_words': 176}