aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/lib
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-09-14 19:58:52 +0200
committerLibravatar GitHub <noreply@github.com>2021-09-14 19:58:52 +0200
commit95df3522a15631abc51a4295cae0ea401a8d4e1e (patch)
treee5eb0f368c947683f01458e912f21756fb0d99cb /src/webview/lib
parentdocs: add sad270 as a contributor for bug, userTesting [skip ci] (#1941) (diff)
downloadferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.gz
ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.zst
ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.zip
feat: add eslint-plugin-unicorn (#1936)
Diffstat (limited to 'src/webview/lib')
-rw-r--r--src/webview/lib/RecipeWebview.js25
-rw-r--r--src/webview/lib/Userscript.js10
2 files changed, 17 insertions, 18 deletions
diff --git a/src/webview/lib/RecipeWebview.js b/src/webview/lib/RecipeWebview.js
index 157da7693..4085b925b 100644
--- a/src/webview/lib/RecipeWebview.js
+++ b/src/webview/lib/RecipeWebview.js
@@ -1,5 +1,5 @@
1import { ipcRenderer } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { exists, pathExistsSync, readFileSync } from 'fs-extra'; 2import { pathExistsSync, readFileSync, existsSync } from 'fs-extra';
3 3
4const debug = require('debug')('Ferdi:Plugin:RecipeWebview'); 4const debug = require('debug')('Ferdi:Plugin:RecipeWebview');
5 5
@@ -62,12 +62,13 @@ class RecipeWebview {
62 * be an absolute path to the file 62 * be an absolute path to the file
63 */ 63 */
64 injectCSS(...files) { 64 injectCSS(...files) {
65 files.forEach(async (file) => { 65 // eslint-disable-next-line unicorn/no-array-for-each
66 files.forEach(file => {
66 if (pathExistsSync(file)) { 67 if (pathExistsSync(file)) {
67 const styles = document.createElement('style'); 68 const styles = document.createElement('style');
68 styles.innerHTML = readFileSync(file, 'utf8'); 69 styles.innerHTML = readFileSync(file, 'utf8');
69 70
70 document.querySelector('head').appendChild(styles); 71 document.querySelector('head').append(styles);
71 72
72 debug('Append styles', styles); 73 debug('Append styles', styles);
73 } 74 }
@@ -75,14 +76,16 @@ class RecipeWebview {
75 } 76 }
76 77
77 injectJSUnsafe(...files) { 78 injectJSUnsafe(...files) {
78 Promise.all(files.map(async (file) => { 79 Promise.all(
79 if (await exists(file)) { 80 files.map(file => {
80 return readFileSync(file, 'utf8'); 81 if (existsSync(file)) {
81 } 82 return readFileSync(file, 'utf8');
82 debug('Script not found', file); 83 }
83 return null; 84 debug('Script not found', file);
84 })).then(async (scripts) => { 85 return null;
85 const scriptsFound = scripts.filter((script) => script !== null); 86 }),
87 ).then(scripts => {
88 const scriptsFound = scripts.filter(script => script !== null);
86 if (scriptsFound.length > 0) { 89 if (scriptsFound.length > 0) {
87 debug('Inject scripts to main world', scriptsFound); 90 debug('Inject scripts to main world', scriptsFound);
88 ipcRenderer.sendToHost('inject-js-unsafe', ...scriptsFound); 91 ipcRenderer.sendToHost('inject-js-unsafe', ...scriptsFound);
diff --git a/src/webview/lib/Userscript.js b/src/webview/lib/Userscript.js
index 2043d9fff..bed2b1ff8 100644
--- a/src/webview/lib/Userscript.js
+++ b/src/webview/lib/Userscript.js
@@ -28,7 +28,7 @@ export default class Userscript {
28 * 28 *
29 * @param {*} settings 29 * @param {*} settings
30 */ 30 */
31 // eslint-disable-next-line 31 // eslint-disable-next-line camelcase
32 internal_setSettings(settings) { 32 internal_setSettings(settings) {
33 // This is needed to get a clean JS object from the settings itself to provide better accessibility 33 // This is needed to get a clean JS object from the settings itself to provide better accessibility
34 // Otherwise this will be a mobX instance 34 // Otherwise this will be a mobX instance
@@ -95,9 +95,7 @@ export default class Userscript {
95 * @param {*} value 95 * @param {*} value
96 */ 96 */
97 set(key, value) { 97 set(key, value) {
98 window.localStorage.setItem( 98 window.localStorage.setItem(`ferdi-user-${key}`, JSON.stringify(value));
99 `ferdi-user-${key}`, JSON.stringify(value),
100 );
101 } 99 }
102 100
103 /** 101 /**
@@ -107,9 +105,7 @@ export default class Userscript {
107 * @return Value of the key 105 * @return Value of the key
108 */ 106 */
109 get(key) { 107 get(key) {
110 return JSON.parse(window.localStorage.getItem( 108 return JSON.parse(window.localStorage.getItem(`ferdi-user-${key}`));
111 `ferdi-user-${key}`,
112 ));
113 } 109 }
114 110
115 /** 111 /**