Skip to content

Commit dad2e68

Browse files
authored
Merge pull request #828 from quoid/fix-console-log-theme-color
fix: add light theme color for console log
2 parents b8f351a + 8572b54 commit dad2e68

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/ext/content-scripts/entry-userscripts.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import USAPI from "./api.js";
2+
import { getColor } from "@shared/colors.js";
23

34
// code received from background page will be stored in this variable
45
// code referenced again when strict CSPs block initial injection attempt
@@ -62,13 +63,13 @@ ${userscript.code}
6263
}
6364
const world = injectInto === "content" ? "content" : "page";
6465
if (window.self === window.top) {
65-
console.info(`Injecting: ${name} %c(js/${world})`, "color: #fff600");
66+
console.info(`Injecting: ${name} %c(js/${world})`, getColor("yellow"));
6667
} else {
6768
console.info(
6869
`Injecting: ${name} %c(js/${world})%c - %cframe(${label})(${window.location})`,
69-
"color: #fff600",
70-
"color: inherit",
71-
"color: #006fff",
70+
getColor("yellow"),
71+
getColor(),
72+
getColor("blue"),
7273
);
7374
}
7475
if (world === "page") {
@@ -94,13 +95,13 @@ ${userscript.code}
9495

9596
function injectCSS(name, code) {
9697
if (window.self === window.top) {
97-
console.info(`Injecting ${name} %c(css)`, "color: #60f36c");
98+
console.info(`Injecting ${name} %c(css)`, getColor("green"));
9899
} else {
99100
console.info(
100101
`Injecting ${name} %c(css)%c - %cframe(${label})(${window.location})`,
101-
"color: #60f36c",
102-
"color: inherit",
103-
"color: #006fff",
102+
getColor("green"),
103+
getColor(),
104+
getColor("blue"),
104105
);
105106
}
106107
// Safari lacks full support for tabs.insertCSS
@@ -246,7 +247,7 @@ function listeners() {
246247
for (let i = 0; i < data.files.menu.length; i++) {
247248
const item = data.files.menu[i];
248249
if (item.scriptObject.filename === filename) {
249-
console.info(`Injecting ${filename} %c(js)`, "color: #fff600");
250+
console.info(`Injecting ${filename} %c(js)`, getColor("yellow"));
250251
injectJS(item);
251252
return;
252253
}

src/shared/colors.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
2+
3+
let isDark = darkModeQuery.matches;
4+
5+
darkModeQuery.addEventListener("change", () => {
6+
isDark = darkModeQuery.matches;
7+
});
8+
9+
/**
10+
* Get theme colors for console log css
11+
* @param {string=} color
12+
*/
13+
export function getColor(color) {
14+
if (!color) return "color: inherit";
15+
const colors = {
16+
blue: { dark: "#006fff", light: "#317eff" },
17+
green: { dark: "#60f36c", light: "#2bb239" },
18+
yellow: { dark: "#fff600", light: "#b8722c" },
19+
};
20+
if (color in colors) {
21+
const hex = isDark ? colors[color].dark : colors[color].light;
22+
return `color: ${hex}`;
23+
}
24+
return "";
25+
}

0 commit comments

Comments
 (0)