Skip to content

Commit 1a71950

Browse files
committed
Select SSL status icon version depending on statusbar color
1 parent 9294afa commit 1a71950

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

common/content/statusline.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,16 @@ const StatusLine = Module("statusline", {
255255
node.style.listStyleImage = window.getComputedStyle(conn_icon).getPropertyValue("list-style-image");
256256
if (node.style.listStyleImage === "none")
257257
node.style.listStyleImage = "url(chrome://browser/skin/identity-icon.svg#normal)";
258-
else
259-
node.style.listStyleImage = node.style.listStyleImage.replace(/-white/, "");
258+
259+
// Get color of bottombar set by ":highlight Normal background: …" as rgb() string
260+
let bbBackgroundColorRGB = window.getComputedStyle(document.getElementById("liberator-bottombar").firstChild).getPropertyValue("background-color");
261+
// Split string into RGB array
262+
let bbBackgroundColor = bbBackgroundColorRGB.substring(4, bbBackgroundColorRGB.length-1).replace(/ /g, '').split(',');
263+
// Calculate (standard) luminance
264+
let bbBackgroundLuminance = 0.2126*bbBackgroundColor[0] + 0.7152*bbBackgroundColor[1] + 0.0722*bbBackgroundColor[2];
265+
// Arbitrary threshold to switch to white-on-black icon
266+
let iconcolor = bbBackgroundLuminance < 128 ? "white" : "black";
267+
node.style.listStyleImage = node.style.listStyleImage.replace(/(#[a-zA-Z-]+)(-white|-black)?/, "$1-" + iconcolor);
260268

261269
node.style.visibility = "visible";
262270

0 commit comments

Comments
 (0)