#109 run script for font color after location change and initial load for already existing badges.

This commit is contained in:
Serraniel 2020-11-14 19:34:51 +01:00
parent a33a047de7
commit a94f7b8519
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -8,11 +8,26 @@ const BADGE_CLASS = 'label';
export function init() {
getGlobalConfiguration().getProperty(SETTINGS_websiteOptimizeFontColors, value => {
if (value) {
core.runAfterLoad(() => {
checkRunColorOptimization(document.documentElement);
}, ".*");
core.runAfterLocationChange(() => {
checkRunColorOptimization(document.documentElement);
}, ".*");
core.registerScript(node => {
checkRunColorOptimization(node);
}, ".*");
}
});
}
function checkRunColorOptimization(node) {
console.log(node);
// run the scripts
if (helper.isHtmlElement(node)) {
if (node.classList.contains(BADGE_CLASS)) {
optimizeFontColorsBadges(node);
}
@ -22,15 +37,15 @@ export function init() {
});
}
}
}, ".*");
}
});
}
function optimizeFontColorsBadges(badge) {
let color = window.getComputedStyle(badge, null).getPropertyValue('background-color');
let c = new Color(color)
if (c.isLight()) {
let colorStr = window.getComputedStyle(badge, null).getPropertyValue('background-color');
if (colorStr.length > 0) { // some elements do not have a computed background color
let color = new Color(colorStr)
if (color.isLight()) {
badge.classList.add('awp-fontColor-dark')
}
}
}