<commit_before>// collection of radio buttons
let level = document.getElementsByName('level');


/**
 * Helper function for browser storage
 * @param {String} strLevel 
 */
function storeA11ycss(strLevel) {
	let a11ycss = { level: strLevel }
	let setting = browser.storage.local.set({ a11ycss });
	setting.then(null, onError); // just in case
}

// store choice when one radio button is chosen
level.forEach(function (key) {
	key.addEventListener('click', function (event ) {
		storeA11ycss(event.target.value);
	});
});


// --------------------------------------

function addA11ycss() {
	let currentLevel = '';
	level.forEach(function (key) {
		if (key.checked == true) {
			currentLevel = key.value;
		}
	});
	console.log(currentLevel);
	const file = `/css/a11y-${locale}_${currentLevel}.css`;
	const code = `
		var oldStylesheet = document.getElementById("${EXTENSION_PREFIX}stylechecker");
		if ( oldStylesheet ) { stylesheet.parentNode.removeChild(oldStylesheet) }
		var stylesheet = document.createElement("link");
		stylesheet.rel = "stylesheet";
		stylesheet.href = ${BROWSER_STRING}.extension.getURL("${file}");
		stylesheet.id = "${EXTENSION_PREFIX}stylechecker";
		document.getElementsByTagName("head")[0].appendChild(stylesheet);
	`;
	console.log(code)
	BROWSER.tabs.executeScript({ code: code });
}

function removeA11ycss() {
	const code = `
		var oldStylesheet = document.getElementById("${EXTENSION_PREFIX}stylechecker");
		if ( oldStylesheet ) { stylesheet.parentNode.removeChild(oldStylesheet) }
	`;
	BROWSER.tabs.executeScript({ code: code });
}

document.getElementById("a11ycssBtnApply").addEventListener('click', function () {
	addA11ycss();
});
document.getElementById("a11ycssBtnClear").addEventListener('click', function () {
	removeA11ycss();
});
// --------------------------------------

// on document load, if we have already chosen a level, give it back
// (the first option is checked in the popup's HTML by default)
function a11ycssOnload() {
	let gettingItem = browser.storage.local.get("a11ycss");
	gettingItem.then(
		// when we got something
		function (item) {
			if (item && item.a11ycss && item.a11ycss.level) { // a level was set already
				console.log("item.a11ycss.level", item.a11ycss.level);
				level.forEach(function (key) {
					if (key.value === item.a11ycss.level) {
						key.checked = true;
					} else {
						key.checked = false;
					}
				});
			}
		},
		// we got nothing
		onError
	);
}
a11ycssOnload();<commit_msg>webext: Removing consoles from a11ycss script - closes #287<commit_after>// collection of radio buttons
let level = document.getElementsByName('level');


/**
 * Helper function for browser storage
 * @param {String} strLevel 
 */
function storeA11ycss(strLevel) {
	let a11ycss = { level: strLevel }
	let setting = browser.storage.local.set({ a11ycss });
	setting.then(null, onError); // just in case
}

// store choice when one radio button is chosen
level.forEach(function (key) {
	key.addEventListener('click', function (event ) {
		storeA11ycss(event.target.value);
	});
});


// --------------------------------------

function addA11ycss() {
	let currentLevel = '';
	level.forEach(function (key) {
		if (key.checked == true) {
			currentLevel = key.value;
		}
	});
	const file = `/css/a11y-${locale}_${currentLevel}.css`;
	const code = `
		var oldStylesheet = document.getElementById("${EXTENSION_PREFIX}stylechecker");
		if ( oldStylesheet ) { stylesheet.parentNode.removeChild(oldStylesheet) }
		var stylesheet = document.createElement("link");
		stylesheet.rel = "stylesheet";
		stylesheet.href = ${BROWSER_STRING}.extension.getURL("${file}");
		stylesheet.id = "${EXTENSION_PREFIX}stylechecker";
		document.getElementsByTagName("head")[0].appendChild(stylesheet);
	`;
	BROWSER.tabs.executeScript({ code: code });
}

function removeA11ycss() {
	const code = `
		var oldStylesheet = document.getElementById("${EXTENSION_PREFIX}stylechecker");
		if ( oldStylesheet ) { stylesheet.parentNode.removeChild(oldStylesheet) }
	`;
	BROWSER.tabs.executeScript({ code: code });
}

document.getElementById("a11ycssBtnApply").addEventListener('click', function () {
	addA11ycss();
});
document.getElementById("a11ycssBtnClear").addEventListener('click', function () {
	removeA11ycss();
});
// --------------------------------------

// on document load, if we have already chosen a level, give it back
// (the first option is checked in the popup's HTML by default)
function a11ycssOnload() {
	let gettingItem = browser.storage.local.get("a11ycss");
	gettingItem.then(
		// when we got something
		function (item) {
			if (item && item.a11ycss && item.a11ycss.level) { // a level was set already
				level.forEach(function (key) {
					if (key.value === item.a11ycss.level) {
						key.checked = true;
					} else {
						key.checked = false;
					}
				});
			}
		},
		// we got nothing
		onError
	);
}
a11ycssOnload();
{'fraction_non_alphanumeric': 0.17477514309076042, 'fraction_numerical': 0.016148814390842193, 'mean_word_length': 3.7093358999037536, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4417527', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1541, 'n_words': 328}