<commit_before>// Initialize variables
const defaultWhiteList = "defaultWhiteList";
const greyPrefix = "-Grey";
let hostUrl;
let activeTab;
let cookieStoreId;
let page = browser.extension.getBackgroundPage().exposedFunctions;

// Logs the error
function onError(error) {
	console.error(`Error: ${error}`);
}

// Fills the popup page
function fillPopup(tabs) {
	browser.storage.local.get("activeMode")
	.then((items) => {
		document.getElementById("activeModeSwitch").checked = items.activeMode;
		return Promise.resolve();
	}).catch(onError);

	let notifyMessage = page.getNotifyMessage();
	if (notifyMessage !== "") {
		document.getElementById("notify").appendChild(document.createTextNode(notifyMessage));
	}
	// Fill the host site placeholder if it exists
	activeTab = tabs[0];
	if (!page.isAWebpage(activeTab.url)) {
		return Promise.resolve();
	}
	hostUrl = page.getHostname(activeTab.url);

	// Sets the checkbox depending on the if it exists in the set
	cookieStoreId = tabs[0].cookieStoreId;
	if (page.contextualIdentitiesEnabled) {
		//document.getElementById("switchToWhiteList").checked = ;
	} else {
		if(page.whiteList.hasHost(hostUrl, defaultWhiteList)) {
			document.getElementById("switchToWhiteList").checked = true;
		} else if(page.whiteList.hasHost(hostUrl, defaultWhiteList + greyPrefix)) {
			document.getElementById("switchToGreyList").checked = true;
		} else {
			document.getElementById("switchToNoList").checked = true;
		}
	}



	// hostUrl = page.extractMainDomain(hostUrl);
	let hostPlaceholder = document.getElementById("hostwebsite");

	// Append the favicon image of the host site to the beggining of the URL

	if (activeTab.favIconUrl) {
		let faviconImage = new Image();
		faviconImage.src = activeTab.favIconUrl;
		faviconImage.style.width = "1em";
		faviconImage.style.height = "1em";
		hostPlaceholder.appendChild(faviconImage);
	}

	// Sets the Host site placeholder
	hostPlaceholder.appendChild(document.createTextNode(hostUrl));
	if (page.contextualIdentitiesEnabled) {
		let name = page.cache.getNameFromCookieID(cookieStoreId);
		hostPlaceholder.appendChild(document.createTextNode(`\n(${name})`));
	}
	return Promise.resolve();
}

browser.tabs.query({
	currentWindow: true,
	active: true
})
.then(fillPopup)
.catch(onError);

function animateSuccess(element) {
	element.classList.add("successAnimated");
	setTimeout(() => {
		element.classList.remove("successAnimated");
	}, 1500);
}

function animateFailure(element) {
	element.classList.add("failureAnimated");
	setTimeout(() => {
		element.classList.remove("failureAnimated");
	}, 1500);
}

// Setting Click Handling
document.getElementById("settings").addEventListener("click", () => {
	browser.runtime.openOptionsPage();
});

// Clear all history for a domain
document.getElementById("cookieCleanup").addEventListener("click", () => {
	page.cleanupOperation(false, false);
	animateSuccess(document.getElementById("cookieCleanup"));
});

document.getElementById("cookieCleanupIgnoreOpenTabs").addEventListener("click", () => {
	page.cleanupOperation(true, false);
	animateSuccess(document.getElementById("cookieCleanupIgnoreOpenTabs"));
});

// Clear all cookies for that domain
document.getElementById("clearCookiesForDomain").addEventListener("click", () => {
	return browser.cookies.getAll({
		domain: hostUrl,
		storeId: cookieStoreId
	})
	.then((cookies) => {
		if (cookies.length > 0) {
			for (let i = 0; i < cookies.length; i++) {
				let cookieDomain = page.prepareCookieDomain(cookies[i]) + cookies[i].path;
				browser.cookies.remove({
					url: cookieDomain,
					name: cookies[i].name,
					storeId: cookieStoreId
				}).catch(onError);
			}
			page.statLog.incrementCounter(cookies.length);
			animateSuccess(document.getElementById("clearCookiesForDomain"));
		} else {
			animateFailure(document.getElementById("clearCookiesForDomain"));
		}
		return Promise.resolve();
	});
});

// Turns on or off active mode cookie cleaning
document.getElementById("activeModeSwitch").addEventListener("click", () => {
	if (document.getElementById("activeModeSwitch").checked) {
		browser.storage.local.set({activeMode: true});
		page.enableActiveMode();
	} else {
		browser.storage.local.set({activeMode: false});
		page.disableActiveMode();
	}
});

// Radio button event Handling

document.getElementById("switchToNoList").addEventListener("click", () => {
	console.log("Removed from list");
	if (hostUrl !== undefined) {
		if (page.contextualIdentitiesEnabled) {
			// if (document.getElementById("switchToWhiteList").checked) {
			// 	page.whiteList.addURL(hostUrl, cookieStoreId);
			// } else {
			// 	page.whiteList.removeURL(hostUrl, cookieStoreId);
			// }
		} else {
			page.whiteList.removeURLFromLists(hostUrl, defaultWhiteList);
		}
		page.checkIfProtected(activeTab);
	}
});

document.getElementById("switchToGreyList").addEventListener("click", () => {
	console.log("Added to GreyList");
	if (hostUrl !== undefined) {
		if (page.contextualIdentitiesEnabled) {
			// if (document.getElementById("switchToWhiteList").checked) {
			// 	page.whiteList.addURL(hostUrl, cookieStoreId);
			// } else {
			// 	page.whiteList.removeURL(hostUrl, cookieStoreId);
			// }
		} else {
			page.whiteList.addURL(hostUrl, defaultWhiteList + greyPrefix);
		}
		page.checkIfProtected(activeTab);
	}
});

document.getElementById("switchToWhiteList").addEventListener("click", () => {
	console.log("Added to WhiteList");
	if (hostUrl !== undefined) {
		if (page.contextualIdentitiesEnabled) {
			// if (document.getElementById("switchToWhiteList").checked) {
			// 	page.whiteList.addURL(hostUrl, cookieStoreId);
			// } else {
			// 	page.whiteList.removeURL(hostUrl, cookieStoreId);
			// }
		} else {
			page.whiteList.addURL(hostUrl, defaultWhiteList);
		}
		page.checkIfProtected(activeTab);
	}
});<commit_msg>Radio Buttons Popup fixes for GreyList in Container Mode<commit_after>// Initialize variables
const defaultWhiteList = "defaultWhiteList";
const greyPrefix = "-Grey";
let hostUrl;
let activeTab;
let cookieStoreId;
let page = browser.extension.getBackgroundPage().exposedFunctions;

// Logs the error
function onError(error) {
	console.error(`Error: ${error}`);
}

// Fills the popup page
function fillPopup(tabs) {
	browser.storage.local.get("activeMode")
	.then((items) => {
		document.getElementById("activeModeSwitch").checked = items.activeMode;
		return Promise.resolve();
	}).catch(onError);

	let notifyMessage = page.getNotifyMessage();
	if (notifyMessage !== "") {
		document.getElementById("notify").appendChild(document.createTextNode(notifyMessage));
	}
	// Fill the host site placeholder if it exists
	activeTab = tabs[0];
	if (!page.isAWebpage(activeTab.url)) {
		return Promise.resolve();
	}
	hostUrl = page.getHostname(activeTab.url);

	// Sets the checkbox depending on the if it exists in the set
	cookieStoreId = tabs[0].cookieStoreId;
	if (page.contextualIdentitiesEnabled) {
		if(page.whiteList.hasHost(hostUrl, cookieStoreId)) {
			document.getElementById("switchToWhiteList").checked = true;
		} else if(page.whiteList.hasHost(hostUrl, cookieStoreId + greyPrefix)) {
			document.getElementById("switchToGreyList").checked = true;
		} else {
			document.getElementById("switchToNoList").checked = true;
		}
	} else {
		if(page.whiteList.hasHost(hostUrl, defaultWhiteList)) {
			document.getElementById("switchToWhiteList").checked = true;
		} else if(page.whiteList.hasHost(hostUrl, defaultWhiteList + greyPrefix)) {
			document.getElementById("switchToGreyList").checked = true;
		} else {
			document.getElementById("switchToNoList").checked = true;
		}
	}



	// hostUrl = page.extractMainDomain(hostUrl);
	let hostPlaceholder = document.getElementById("hostwebsite");

	// Append the favicon image of the host site to the beggining of the URL

	if (activeTab.favIconUrl) {
		let faviconImage = new Image();
		faviconImage.src = activeTab.favIconUrl;
		faviconImage.style.width = "1em";
		faviconImage.style.height = "1em";
		hostPlaceholder.appendChild(faviconImage);
	}

	// Sets the Host site placeholder
	hostPlaceholder.appendChild(document.createTextNode(hostUrl));
	if (page.contextualIdentitiesEnabled) {
		let name = page.cache.getNameFromCookieID(cookieStoreId);
		hostPlaceholder.appendChild(document.createTextNode(`\n(${name})`));
	}
	return Promise.resolve();
}

browser.tabs.query({
	currentWindow: true,
	active: true
})
.then(fillPopup)
.catch(onError);

function animateSuccess(element) {
	element.classList.add("successAnimated");
	setTimeout(() => {
		element.classList.remove("successAnimated");
	}, 1500);
}

function animateFailure(element) {
	element.classList.add("failureAnimated");
	setTimeout(() => {
		element.classList.remove("failureAnimated");
	}, 1500);
}

// Setting Click Handling
document.getElementById("settings").addEventListener("click", () => {
	browser.runtime.openOptionsPage();
});

// Clear all history for a domain
document.getElementById("cookieCleanup").addEventListener("click", () => {
	page.cleanupOperation(false, false);
	animateSuccess(document.getElementById("cookieCleanup"));
});

document.getElementById("cookieCleanupIgnoreOpenTabs").addEventListener("click", () => {
	page.cleanupOperation(true, false);
	animateSuccess(document.getElementById("cookieCleanupIgnoreOpenTabs"));
});

// Clear all cookies for that domain
document.getElementById("clearCookiesForDomain").addEventListener("click", () => {
	return browser.cookies.getAll({
		domain: hostUrl,
		storeId: cookieStoreId
	})
	.then((cookies) => {
		if (cookies.length > 0) {
			for (let i = 0; i < cookies.length; i++) {
				let cookieDomain = page.prepareCookieDomain(cookies[i]) + cookies[i].path;
				browser.cookies.remove({
					url: cookieDomain,
					name: cookies[i].name,
					storeId: cookieStoreId
				}).catch(onError);
			}
			page.statLog.incrementCounter(cookies.length);
			animateSuccess(document.getElementById("clearCookiesForDomain"));
		} else {
			animateFailure(document.getElementById("clearCookiesForDomain"));
		}
		return Promise.resolve();
	});
});

// Turns on or off active mode cookie cleaning
document.getElementById("activeModeSwitch").addEventListener("click", () => {
	if (document.getElementById("activeModeSwitch").checked) {
		browser.storage.local.set({activeMode: true});
		page.enableActiveMode();
	} else {
		browser.storage.local.set({activeMode: false});
		page.disableActiveMode();
	}
});

// Radio button event Handling

document.getElementById("switchToNoList").addEventListener("click", () => {
	console.log("Removed from list");
	if (hostUrl !== undefined) {
		page.whiteList.removeURLFromLists(hostUrl, cookieStoreId);
		page.checkIfProtected(activeTab);
	}
});

document.getElementById("switchToGreyList").addEventListener("click", () => {
	console.log("Added to GreyList");
	if (hostUrl !== undefined) {
		if (page.contextualIdentitiesEnabled) {
			page.whiteList.addURL(hostUrl, cookieStoreId + greyPrefix);
		} else {
			page.whiteList.addURL(hostUrl, defaultWhiteList + greyPrefix);
		}
		page.checkIfProtected(activeTab);
	}
});

document.getElementById("switchToWhiteList").addEventListener("click", () => {
	console.log("Added to WhiteList");
	if (hostUrl !== undefined) {
		if (page.contextualIdentitiesEnabled) {
			page.whiteList.addURL(hostUrl, cookieStoreId);
		} else {
			page.whiteList.addURL(hostUrl, defaultWhiteList);
		}
		page.checkIfProtected(activeTab);
	}
});
{'fraction_non_alphanumeric': 0.14642072902942468, 'fraction_numerical': 0.0024593763724198507, 'mean_word_length': 5.339643652561247, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '5490543', 'n_tokens_mistral': 3679, 'n_tokens_neox': 3408, 'n_words': 601}