#109 run script for font color after location change and initial load for already existing badges.
This commit is contained in:
parent
a33a047de7
commit
a94f7b8519
|
@ -7,30 +7,45 @@ const BADGE_CLASS = 'label';
|
||||||
|
|
||||||
export function init() {
|
export function init() {
|
||||||
getGlobalConfiguration().getProperty(SETTINGS_websiteOptimizeFontColors, value => {
|
getGlobalConfiguration().getProperty(SETTINGS_websiteOptimizeFontColors, value => {
|
||||||
if (value) {
|
if (value) {
|
||||||
core.registerScript(node => {
|
core.runAfterLoad(() => {
|
||||||
console.log(node);
|
checkRunColorOptimization(document.documentElement);
|
||||||
// run the scripts
|
}, ".*");
|
||||||
if (helper.isHtmlElement(node)) {
|
|
||||||
|
|
||||||
if (node.classList.contains(BADGE_CLASS)) {
|
core.runAfterLocationChange(() => {
|
||||||
optimizeFontColorsBadges(node);
|
checkRunColorOptimization(document.documentElement);
|
||||||
}
|
}, ".*");
|
||||||
else {
|
|
||||||
node.querySelectorAll(`.${BADGE_CLASS}`).forEach(element => {
|
core.registerScript(node => {
|
||||||
optimizeFontColorsBadges(element);
|
checkRunColorOptimization(node);
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, ".*");
|
}, ".*");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkRunColorOptimization(node) {
|
||||||
|
console.log(node);
|
||||||
|
|
||||||
|
// run the scripts
|
||||||
|
if (helper.isHtmlElement(node)) {
|
||||||
|
if (node.classList.contains(BADGE_CLASS)) {
|
||||||
|
optimizeFontColorsBadges(node);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node.querySelectorAll(`.${BADGE_CLASS}`).forEach(element => {
|
||||||
|
optimizeFontColorsBadges(element);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function optimizeFontColorsBadges(badge) {
|
function optimizeFontColorsBadges(badge) {
|
||||||
let color = window.getComputedStyle(badge, null).getPropertyValue('background-color');
|
let colorStr = window.getComputedStyle(badge, null).getPropertyValue('background-color');
|
||||||
let c = new Color(color)
|
|
||||||
if (c.isLight()) {
|
if (colorStr.length > 0) { // some elements do not have a computed background color
|
||||||
badge.classList.add('awp-fontColor-dark')
|
let color = new Color(colorStr)
|
||||||
|
if (color.isLight()) {
|
||||||
|
badge.classList.add('awp-fontColor-dark')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue