aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/darkmode.ts
diff options
context:
space:
mode:
authorLibravatar Vijay A <vraravam@users.noreply.github.com>2021-10-29 05:58:33 +0530
committerLibravatar Vijay A <vraravam@users.noreply.github.com>2021-10-29 05:58:33 +0530
commita956ab9c9f3c571232118babe699709c9e0144d7 (patch)
treee612be3f6df3ccae0635400c64c1b9ec65b4bd87 /src/webview/darkmode.ts
parentUpdate submodules, browserslist data updates and linter fixes [skip ci] (diff)
downloadferdium-app-a956ab9c9f3c571232118babe699709c9e0144d7.tar.gz
ferdium-app-a956ab9c9f3c571232118babe699709c9e0144d7.tar.zst
ferdium-app-a956ab9c9f3c571232118babe699709c9e0144d7.zip
refactor: Remove duplicate code
Diffstat (limited to 'src/webview/darkmode.ts')
-rw-r--r--src/webview/darkmode.ts13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/webview/darkmode.ts b/src/webview/darkmode.ts
index 7b9407049..a0699bdb7 100644
--- a/src/webview/darkmode.ts
+++ b/src/webview/darkmode.ts
@@ -9,10 +9,17 @@ const ID = [...Array.from({ length: 20 })]
9 .map(() => chars[Math.trunc(Math.random() * chars.length)]) 9 .map(() => chars[Math.trunc(Math.random() * chars.length)])
10 .join(''); 10 .join('');
11 11
12function darkModeFilePath(recipePath: string) {
13 return join(recipePath, 'darkmode.css');
14}
15
16export function darkModeStyleExists(recipePath: string) {
17 return pathExistsSync(darkModeFilePath(recipePath));
18}
19
12export function injectDarkModeStyle(recipePath: string) { 20export function injectDarkModeStyle(recipePath: string) {
13 const darkModeStyle = join(recipePath, 'darkmode.css'); 21 if (darkModeStyleExists(recipePath)) {
14 if (pathExistsSync(darkModeStyle)) { 22 const data = readFileSync(darkModeFilePath(recipePath));
15 const data = readFileSync(darkModeStyle);
16 const styles = document.createElement('style'); 23 const styles = document.createElement('style');
17 styles.id = ID; 24 styles.id = ID;
18 styles.innerHTML = data.toString(); 25 styles.innerHTML = data.toString();