<commit_before>'use strict';

define((require) => {
	const Util = require('util/util');
	const Config = require('storage/config');
	const ChromeStorage = require('storage/chrome-storage');

	const options = ChromeStorage.getStorage(ChromeStorage.OPTIONS);
	const sortedConnectors = Util.getSortedConnectors();

	async function initialize() {
		await initConnectorsList();
	}

	async function initConnectorsList() {
		const parent = $('ul#connectors');

		let toggleCheckboxState = false;
		const data = await options.get();
		const disabledConnectors = data.disabledConnectors;

		sortedConnectors.forEach((connector, index) => {
			const newEl = $(`
				<li>
					<a href="#" class="conn-config" data-conn="${index}">
						<i class="fa fa-gear fa-fw"></i>
					</a>
					<input type="checkbox" id="conn-${index}">
					<label for="conn-${index}">${connector.label}</label>
				</li>
			`);

			const domEl = newEl.appendTo(parent);
			const checkbox = domEl.find('input');

			checkbox.click(function() {
				Config.setConnectorEnabled(connector.label, this.checked);
			});
			const isConnectorEnabled = !disabledConnectors.includes(connector.label);
			checkbox.attr('checked', isConnectorEnabled);

			if (isConnectorEnabled) {
				toggleCheckboxState = true;
			}
		});

		$('input#toggle').attr('checked', toggleCheckboxState);
		$('input#toggle').click(function() {
			// First set each to the negated value and then trigger click
			$('input[id^="conn"]').each((index, connector) => {
				$(connector).prop('checked', this.checked);
			});
			Config.setAllConnectorsEnabled(this.checked);
		});
	}

	return { initialize };
});
<commit_msg>Simplify toggle checkbox initialization<commit_after>'use strict';

define((require) => {
	const Util = require('util/util');
	const Config = require('storage/config');
	const ChromeStorage = require('storage/chrome-storage');

	const options = ChromeStorage.getStorage(ChromeStorage.OPTIONS);
	const sortedConnectors = Util.getSortedConnectors();

	async function initialize() {
		await initConnectorsList();
	}

	async function initConnectorsList() {
		const parent = $('ul#connectors');

		const data = await options.get();
		const disabledConnectors = data.disabledConnectors;
		const toggleCheckboxState =
			disabledConnectors.length !== sortedConnectors.length;

		sortedConnectors.forEach((connector, index) => {
			const newEl = $(`
				<li>
					<a href="#" class="conn-config" data-conn="${index}">
						<i class="fa fa-gear fa-fw"></i>
					</a>
					<input type="checkbox" id="conn-${index}">
					<label for="conn-${index}">${connector.label}</label>
				</li>
			`);

			const domEl = newEl.appendTo(parent);
			const checkbox = domEl.find('input');

			checkbox.click(function() {
				Config.setConnectorEnabled(connector.label, this.checked);
			});
			const isConnectorEnabled = !disabledConnectors.includes(connector.label);
			checkbox.attr('checked', isConnectorEnabled);
		});

		$('input#toggle').attr('checked', toggleCheckboxState);
		$('input#toggle').click(function() {
			// First set each to the negated value and then trigger click
			$('input[id^="conn"]').each((index, connector) => {
				$(connector).prop('checked', this.checked);
			});
			Config.setAllConnectorsEnabled(this.checked);
		});
	}

	return { initialize };
});

{'fraction_non_alphanumeric': 0.16596130592503022, 'fraction_numerical': 0.0, 'mean_word_length': 4.505823627287854, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, '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': '4860870', 'n_tokens_mistral': 1148, 'n_tokens_neox': 987, 'n_words': 196}