diff options
author | 2021-11-18 17:37:45 +0100 | |
---|---|---|
committer | 2021-11-18 22:07:45 +0530 | |
commit | b37a6b07b39c8c7827052dc6fb97f490f1e0f514 (patch) | |
tree | 0276e7c51f5ebfa14c566def7aac39f014c2291d /src/webview/lib/Userscript.js | |
parent | Update github issues template [skip ci] (diff) | |
download | ferdium-app-b37a6b07b39c8c7827052dc6fb97f490f1e0f514.tar.gz ferdium-app-b37a6b07b39c8c7827052dc6fb97f490f1e0f514.tar.zst ferdium-app-b37a6b07b39c8c7827052dc6fb97f490f1e0f514.zip |
chore: convert various files to TS (#2246)
* convert various files to TS
* removed outdated docs/example-feature folder
* turn off unicorn/no-empty-file
* update eslint config
Diffstat (limited to 'src/webview/lib/Userscript.js')
-rw-r--r-- | src/webview/lib/Userscript.js | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/src/webview/lib/Userscript.js b/src/webview/lib/Userscript.js deleted file mode 100644 index f7bb99206..000000000 --- a/src/webview/lib/Userscript.js +++ /dev/null | |||
@@ -1,138 +0,0 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
2 | |||
3 | export default class Userscript { | ||
4 | // Current ./lib/RecipeWebview instance | ||
5 | recipe = null; | ||
6 | |||
7 | // Current ./recipe.js instance | ||
8 | controller = null; | ||
9 | |||
10 | // Service configuration | ||
11 | config = {}; | ||
12 | |||
13 | // Ferdi and service settings | ||
14 | settings = {}; | ||
15 | |||
16 | settingsUpdateHandler = null; | ||
17 | |||
18 | constructor(recipe, controller, config) { | ||
19 | this.recipe = recipe; | ||
20 | this.controller = controller; | ||
21 | this.internal_setSettings(controller.settings); | ||
22 | this.config = config; | ||
23 | } | ||
24 | |||
25 | /** | ||
26 | * Set internal copy of Ferdi's settings. | ||
27 | * This is only used internally and can not be used to change any settings | ||
28 | * | ||
29 | * @param {*} settings | ||
30 | */ | ||
31 | // eslint-disable-next-line camelcase | ||
32 | internal_setSettings(settings) { | ||
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 | ||
35 | this.settings = JSON.parse(JSON.stringify(settings)); | ||
36 | |||
37 | if (typeof this.settingsUpdateHandler === 'function') { | ||
38 | this.settingsUpdateHandler(); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Register a settings handler to be executed when the settings change | ||
44 | * | ||
45 | * @param {function} handler | ||
46 | */ | ||
47 | onSettingsUpdate(handler) { | ||
48 | this.settingsUpdateHandler = handler; | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Set badge count for the current service | ||
53 | * @param {*} direct Direct messages | ||
54 | * @param {*} indirect Indirect messages | ||
55 | */ | ||
56 | setBadge(direct = 0, indirect = 0) { | ||
57 | if (this.recipe && this.recipe.setBadge) { | ||
58 | this.recipe.setBadge(direct, indirect); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Set active dialog title to the app title | ||
64 | * @param {*} title Dialog title | ||
65 | */ | ||
66 | setDialogTitle(title) { | ||
67 | if (this.recipe && this.recipe.setDialogTitle) { | ||
68 | this.recipe.setDialogTitle(title); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * Inject CSS files into the current page | ||
74 | * | ||
75 | * @param {...string} files | ||
76 | */ | ||
77 | injectCSSFiles(...files) { | ||
78 | if (this.recipe && this.recipe.injectCSS) { | ||
79 | this.recipe.injectCSS(...files); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * Inject a CSS string into the page | ||
85 | * | ||
86 | * @param {string} css | ||
87 | */ | ||
88 | injectCSS(css) { | ||
89 | const style = document.createElement('style'); | ||
90 | style.textContent = css; | ||
91 | document.head.append(style); | ||
92 | } | ||
93 | |||
94 | /** | ||
95 | * Open "Find in Page" popup | ||
96 | */ | ||
97 | openFindInPage() { | ||
98 | this.controller.openFindInPage(); | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * Set or update value in storage | ||
103 | * | ||
104 | * @param {*} key | ||
105 | * @param {*} value | ||
106 | */ | ||
107 | set(key, value) { | ||
108 | window.localStorage.setItem(`ferdi-user-${key}`, JSON.stringify(value)); | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * Get value from storage | ||
113 | * | ||
114 | * @param {*} key | ||
115 | * @return Value of the key | ||
116 | */ | ||
117 | get(key) { | ||
118 | return JSON.parse(window.localStorage.getItem(`ferdi-user-${key}`)); | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * Open a URL in an external browser | ||
123 | * | ||
124 | * @param {*} url | ||
125 | */ | ||
126 | externalOpen(url) { | ||
127 | ipcRenderer.sendToHost('new-window', url); | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * Open a URL in the current service | ||
132 | * | ||
133 | * @param {*} url | ||
134 | */ | ||
135 | internalOpen(url) { | ||
136 | window.location.href = url; | ||
137 | } | ||
138 | } | ||