<commit_before>"use strict";

function orTrue(v) {
	return typeof v === "boolean" ? v : true;
}

function assert(condition, message) {
	if(!condition) {
		throw message || "Assertion failed";
	}
}

const settings = {
	muteNewTabs:           true,
	muteOnOriginChange:    true,
	muteAllTabsOnStartup:  true,
	unmuteOnVolumeControl: true
}

// Populate settings as soon as possible
chrome.storage.local.get(['muteNewTabs', 'muteOnOriginChange', 'muteAllTabsOnStartup', 'unmuteOnVolumeControl'], function(result) {
	settings.muteNewTabs           = orTrue(result.muteNewTabs);
	settings.muteOnOriginChange    = orTrue(result.muteOnOriginChange);
	settings.muteAllTabsOnStartup  = orTrue(result.muteAllTabsOnStartup);
	settings.unmuteOnVolumeControl = orTrue(result.unmuteOnVolumeControl);

	if(settings.muteAllTabsOnStartup) {
		muteAllTabs();
	}
});

function keyChanged(key, newValue) {
	assert(typeof key === "string");
	if(settings.hasOwnProperty(key)) {
		settings[key] = orTrue(newValue);
	}
}

function storageChanged(changes, namespace) {
	for(const key in changes) {
		var storageChange = changes[key];
		console.log(
			"Storage key", key, "in namespace", namespace, "changed.",
			"Old value was", storageChange.oldValue, "; new value is", storageChange.newValue
		);
		keyChanged(key, storageChange.newValue);
	}
}

function muteTab(tabId) {
	assert(Number.isInteger(tabId));
	chrome.tabs.update(tabId, {muted: true});
}

function unmuteTab(tabId) {
	assert(Number.isInteger(tabId));
	chrome.tabs.update(tabId, {muted: false});
}

function muteAllTabs() {
	chrome.tabs.query({}, function(tabs) {
		for(const tab of tabs) {
			muteTab(tab.id);<commit_msg>var -> const<commit_after>"use strict";

function orTrue(v) {
	return typeof v === "boolean" ? v : true;
}

function assert(condition, message) {
	if(!condition) {
		throw message || "Assertion failed";
	}
}

const settings = {
	muteNewTabs:           true,
	muteOnOriginChange:    true,
	muteAllTabsOnStartup:  true,
	unmuteOnVolumeControl: true
}

// Populate settings as soon as possible
chrome.storage.local.get(['muteNewTabs', 'muteOnOriginChange', 'muteAllTabsOnStartup', 'unmuteOnVolumeControl'], function(result) {
	settings.muteNewTabs           = orTrue(result.muteNewTabs);
	settings.muteOnOriginChange    = orTrue(result.muteOnOriginChange);
	settings.muteAllTabsOnStartup  = orTrue(result.muteAllTabsOnStartup);
	settings.unmuteOnVolumeControl = orTrue(result.unmuteOnVolumeControl);

	if(settings.muteAllTabsOnStartup) {
		muteAllTabs();
	}
});

function keyChanged(key, newValue) {
	assert(typeof key === "string");
	if(settings.hasOwnProperty(key)) {
		settings[key] = orTrue(newValue);
	}
}

function storageChanged(changes, namespace) {
	for(const key in changes) {
		const storageChange = changes[key];
		console.log(
			"Storage key", key, "in namespace", namespace, "changed.",
			"Old value was", storageChange.oldValue, "; new value is", storageChange.newValue
		);
		keyChanged(key, storageChange.newValue);
	}
}

function muteTab(tabId) {
	assert(Number.isInteger(tabId));
	chrome.tabs.update(tabId, {muted: true});
}

function unmuteTab(tabId) {
	assert(Number.isInteger(tabId));
	chrome.tabs.update(tabId, {muted: false});
}

function muteAllTabs() {
	chrome.tabs.query({}, function(tabs) {
		for(const tab of tabs) {
			muteTab(tab.id);
{'fraction_non_alphanumeric': 0.13766155695822063, 'fraction_numerical': 0.0, 'mean_word_length': 5.279245283018868, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6737375', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1158, 'n_words': 214}