Skip to content

Commit

Permalink
Fix hints not being shown with new color spaces in CSS Colors v4
Browse files Browse the repository at this point in the history
  • Loading branch information
david-tejada committed Dec 7, 2023
1 parent 770e581 commit 36af841
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/content/hints/HintClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,12 @@ export class HintClass implements Hint {
} else {
const elementToGetColorFrom =
this.firstTextNodeDescendant?.parentElement;
const colorString = window.getComputedStyle(
let colorString = window.getComputedStyle(
elementToGetColorFrom ?? this.target
).color;
colorString = colorString.startsWith("rgb")
? colorString
: "rgb(0, 0, 0)";
color = rgbaToRgb(new Color(colorString || "black"), backgroundColor);

if (!elementToGetColorFrom) {
Expand Down
6 changes: 5 additions & 1 deletion src/content/utils/getEffectiveBackgroundColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export function getEffectiveBackgroundColor(element: Element) {
let current: Element | null = element;

while (current) {
const { backgroundColor } = window.getComputedStyle(current);
let { backgroundColor } = window.getComputedStyle(current);

if (!backgroundColor.startsWith("rgb")) {
backgroundColor = "rgb(255, 255, 255)";
}

if (backgroundColor && backgroundColor !== "rgba(0, 0, 0, 0)") {
if (isRgb(backgroundColor)) {
Expand Down

0 comments on commit 36af841

Please sign in to comment.