Skip to content

Commit

Permalink
Support dark mode colors, remove Mac hackery
Browse files Browse the repository at this point in the history
We no longer need special code for mac.
  • Loading branch information
ericlaw1979 committed Jul 1, 2021
1 parent 78af99d commit 01844f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
45 changes: 17 additions & 28 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,32 @@ function updateUI() {
sMajorVer = /Edg\/([0-9]+)/.exec(navigator.userAgent)[1];
sMinorVer = /Edg\/[0-9]+\.[0-9]+\.([0-9]+)/.exec(navigator.userAgent)[1];
}
const allColors = ["purple", "blue", "green", "black"];
const bIsMac = navigator.userAgent.includes("Mac OS X");

const myColor = allColors[sMajorVer % allColors.length];
// Select color palette based on dark/light theme. Use light colors on
// Dark Mode and vice-versa.
const bDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
const arrDarkColors = ["purple", "blue", "green", "black"];
const arrColors = bDarkMode ? ["fuchsia", "aqua", "lime", "white"]
: arrDarkColors;

const myColor = arrColors[sMajorVer % arrColors.length];
const myBadgeColor = arrDarkColors[sMajorVer % arrDarkColors.length];
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');

var imageData;
if (bIsMac) {
/* On OS X we need to draw our own minor version
text because the badge truncates. It's unappealing to
do this in general because on Windows at least, using
the badge gives us a bit more vertical space. */

ctx.font = "bold 28px Verdana";
ctx.fillStyle = myColor;
ctx.fillText(sMajorVer, 0, 22);
ctx.font = "18px Arial Narrow";
ctx.fillText(sMinorVer, 3, 38);
imageData = ctx.getImageData(0, 0, 38, 38);
chrome.browserAction.setBadgeText( {text: ""} );
}
else {
ctx.font = "14px Verdana";
ctx.strokeStyle = myColor;
ctx.strokeText(sMajorVer, 1, 11);
imageData = ctx.getImageData(0, 0, 19, 19);
}
ctx.font = "14px Verdana";
ctx.strokeStyle = myColor;
ctx.strokeText(sMajorVer, 1, 11);
imageData = ctx.getImageData(0, 0, 19, 19);

try {
chrome.browserAction.setIcon({ imageData: imageData });
chrome.browserAction.setTitle({ title: navigator.userAgent.replace("Mozilla/5.0", "") });
if (!bIsMac) {
chrome.browserAction.setBadgeText( {text: sMinorVer} );
chrome.browserAction.setBadgeBackgroundColor({color: myColor});
}
} catch (e) { console.error(e); }
chrome.browserAction.setBadgeText( {text: sMinorVer} );
chrome.browserAction.setBadgeBackgroundColor({color: myBadgeColor});
}
catch (e) { console.error(e); }
}

// There's a pending update available; user must restart the browser.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"short_name": "ShowChromeVersion",
"description": "Show browser version information in the toolbar.",
"content_security_policy": "default-src 'self'",
"version": "1.0.1.0",
"version": "1.0.2.0",
"author": "Eric Lawrence (@ericlaw)",
"minimum_chrome_version": "48",

Expand Down

0 comments on commit 01844f9

Please sign in to comment.