diff options
author | 2020-02-26 12:12:02 +0100 | |
---|---|---|
committer | 2020-02-26 12:12:02 +0100 | |
commit | ce988c280f5ca6dfc202d209e66d7cfce257c43b (patch) | |
tree | f469740cba0141af5b15a50b764a79f0b9b84a91 /src/webview/recipe.js | |
parent | Avoid AppVeyor builds on i18n-only commits (diff) | |
download | ferdium-app-ce988c280f5ca6dfc202d209e66d7cfce257c43b.tar.gz ferdium-app-ce988c280f5ca6dfc202d209e66d7cfce257c43b.tar.zst ferdium-app-ce988c280f5ca6dfc202d209e66d7cfce257c43b.zip |
Implement user.css and user.js (#401)
* #83 Implement user.css and user.js
* Fix button layout in settings
* Fix user script not loading
Co-authored-by: Amine <amine@mouafik.fr>
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() { |