ignore foreground/background colour in spans when night mode active

This prevents pasted text from a standard webpage appearing as
black on white. It could theoretically be made smarter in the future,
but handling all the situations where the background or foreground
colour is not exactly #000/#fff might be tricky.
This commit is contained in:
Damien Elmes 2020-01-31 08:03:09 +10:00
parent 32b279f750
commit eb6b64f4b1

View file

@ -464,6 +464,10 @@ const allowedStyling = {
"text-decoration-line": true,
};
let isNightMode = function(): boolean {
return document.body.classList.contains("nightMode");
};
let filterExternalSpan = function(node) {
// filter out attributes
let toRemove = [];
@ -486,6 +490,12 @@ let filterExternalSpan = function(node) {
// google docs adds this unnecessarily
toRemove.push(name);
}
if (isNightMode()) {
// ignore coloured text in night mode for now
if (name === "background-color" || name == "color") {
toRemove.push(name);
}
}
}
for (let name of toRemove) {
node.style.removeProperty(name);