globalThis.flipColors = function(lightColorMap) {
	if (!globalThis.savedColorMap) {
		globalThis.savedColorMap = setColors(lightColorMap);
	} else {
		restoreColors(globalThis.savedColorMap);
		globalThis.savedColorMap = null;
	}
};

globalThis.setColors = function(colorMap) {
	let originalState = [];
	let props = ["color", "backgroundColor", "backgroundImage"];
	let styleSheetArray = Array.from(document.styleSheets);
	styleSheetArray.forEach(styleSheet => {
		try {
			let cssRules = Array.from(styleSheet.cssRules);
			cssRules.forEach(cssRule => {
				if (cssRule.type === 1) {
					props.forEach(propName => {
						let currentValue = cssRule.style[propName];
						if (
							currentValue !== "" &&
							currentValue !== "inherit" &&
							currentValue !== "transparent") {
							let newVal = colorMap[currentValue];
							if (typeof newVal !== "undefined") {
								cssRule.style[propName] = newVal;
								originalState.push({
									element: cssRule,
									propName: propName,
									value: currentValue
								});
							}
						}
					});
				}
			});
		} catch (error) {
			// No need to do anthing, this is expected when there are user style sheets.
		}
	});
	return originalState;
};

globalThis.restoreColors = function(styleMap) {
	styleMap.forEach(
		item => {
			item.element.style[item.propName] = item.value;
		}
	);
};

src/js/colorModeJS.js