diff options
Diffstat (limited to 'src/webview/recipe.js')
-rw-r--r-- | src/webview/recipe.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index e95cae18b..1a22542d8 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -99,6 +99,39 @@ class RecipeController { | |||
99 | } catch (err) { | 99 | } catch (err) { |
100 | console.error('Recipe initialization failed', err); | 100 | console.error('Recipe initialization failed', err); |
101 | } | 101 | } |
102 | |||
103 | this.loadUserFiles(recipe, config); | ||
104 | } | ||
105 | |||
106 | async loadUserFiles(recipe, config) { | ||
107 | const userCss = path.join(recipe.path, 'user.css'); | ||
108 | if (await fs.exists(userCss)) { | ||
109 | const data = await fs.readFile(userCss); | ||
110 | const styles = document.createElement('style'); | ||
111 | styles.innerHTML = data.toString(); | ||
112 | |||
113 | document.querySelector('head').appendChild(styles); | ||
114 | } | ||
115 | |||
116 | const userJs = path.join(recipe.path, 'user.js'); | ||
117 | if (await fs.exists(userJs)) { | ||
118 | const loadUserJs = () => { | ||
119 | // eslint-disable-next-line | ||
120 | const userJsModule = require(userJs); | ||
121 | |||
122 | if (typeof userJsModule === 'function') { | ||
123 | userJsModule(config); | ||
124 | } | ||
125 | }; | ||
126 | |||
127 | if (document.readyState !== 'loading') { | ||
128 | loadUserJs(); | ||
129 | } else { | ||
130 | document.addEventListener('DOMContentLoaded', () => { | ||
131 | loadUserJs(); | ||
132 | }); | ||
133 | } | ||
134 | } | ||
102 | } | 135 | } |
103 | 136 | ||
104 | update() { | 137 | update() { |