pardus-options-library 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +323 -0
  2. package/eslint.config.js +38 -0
  3. package/package.json +32 -0
  4. package/src/classes/abstract/abstract-button.js +116 -0
  5. package/src/classes/abstract/abstract-toggle-button.js +145 -0
  6. package/src/classes/contents-area.js +22 -0
  7. package/src/classes/description-element.js +80 -0
  8. package/src/classes/disableable-html-element.js +48 -0
  9. package/src/classes/html-element.js +189 -0
  10. package/src/classes/info-element.js +56 -0
  11. package/src/classes/options/abstract-array-option.js +38 -0
  12. package/src/classes/options/abstract-option.js +189 -0
  13. package/src/classes/options/boolean-option.js +24 -0
  14. package/src/classes/options/grouped-options.js +61 -0
  15. package/src/classes/options/key-down-disable-button.js +20 -0
  16. package/src/classes/options/key-down-option.js +178 -0
  17. package/src/classes/options/key-down-set-key-button.js +18 -0
  18. package/src/classes/options/numeric-option.js +40 -0
  19. package/src/classes/options/select-option.js +74 -0
  20. package/src/classes/options/text-area-option.js +39 -0
  21. package/src/classes/options-box.js +200 -0
  22. package/src/classes/options-content.js +178 -0
  23. package/src/classes/options-group.js +114 -0
  24. package/src/classes/pardus-options-utility.js +139 -0
  25. package/src/classes/pardus-options.js +144 -0
  26. package/src/classes/save-button-row/load-button.js +21 -0
  27. package/src/classes/save-button-row/preset-label.js +95 -0
  28. package/src/classes/save-button-row/preset-row.js +106 -0
  29. package/src/classes/save-button-row/presets.js +57 -0
  30. package/src/classes/save-button-row/reset-button.js +21 -0
  31. package/src/classes/save-button-row/save-button-row.js +69 -0
  32. package/src/classes/save-button-row/save-button.js +21 -0
  33. package/src/classes/tabs/sub-tab.js +66 -0
  34. package/src/classes/tabs/tab-content.js +149 -0
  35. package/src/classes/tabs/tab-label.js +45 -0
  36. package/src/classes/tabs/tab.js +66 -0
  37. package/src/classes/tabs/tabs-element.js +25 -0
  38. package/src/classes/tabs/tabs-row.js +44 -0
  39. package/src/classes/tip-box.js +69 -0
  40. package/src/classes/version-row.js +14 -0
  41. package/src/index.js +13 -0
  42. package/webpack.config.cjs +16 -0
package/README.md ADDED
@@ -0,0 +1,323 @@
1
+ # Pardus-Options-Library
2
+ The Pardus Options Library is a script designed to add useful and easy ways to interact with the Options page within other scripts related to the online game Pardus (https://pardus.at). It is written entirely in ECMAScript 6.
3
+
4
+ ## Installation
5
+ At the top of your Tampermonkey script, ensure you have the following lines:
6
+ ```javascript
7
+ // @include http*://*.pardus.at/options.php
8
+ // @grant GM_setValue
9
+ // @grant GM_getValue
10
+ // @require https://raw.githubusercontent.com/Tro95/Pardus-Options-Library/v2.6.1/dist/pardus-options-library.js
11
+ ```
12
+ The `GM_setValue` and `GM_getValue` methods are required to persistently store the user's settings.
13
+
14
+ ### Multiple Scripts
15
+
16
+ This library is safe to be included by multiple scripts.
17
+
18
+ ## Building the Library
19
+
20
+ If you wish to build the library from source, you can do this simply by running `npm run build`
21
+
22
+ ## Usage
23
+
24
+ Within your script you should check `document.location.pathname` to see if you're on the `options.php` page, as the library is only defined and available on this page.
25
+ ```javascript
26
+ if (document.location.pathname === '/options.php') {
27
+ // Option-related logic goes here
28
+ }
29
+ ```
30
+ The library is available through a static object `PardusOptions`. It is recommended to abstract your options logic into a separate function.
31
+
32
+ ```javascript
33
+ function myOptionsLogic() {
34
+ /**
35
+ * Create the tab for your script
36
+ */
37
+ const myScriptsTab = PardusOptions.addTab({
38
+ heading: 'My Script',
39
+ id: 'my-script'
40
+ });
41
+
42
+ /**
43
+ * Create a box for your options
44
+ */
45
+ const mainOptionsBox = myScriptsTab.addBox({
46
+ heading: 'Main Options',
47
+ description: 'These are the main options for my script'
48
+ });
49
+
50
+ /**
51
+ * Create a boolean option, and bind it to the universe-specific variable.
52
+ */
53
+ const mainOptionsBox.addBooleanOption({
54
+ variable: 'enable_super_cool_feature',
55
+ description: 'Enable the super cool feature',
56
+ defaultValue: true
57
+ });
58
+ }
59
+
60
+ if (document.location.pathname === '/options.php') {
61
+ // Call the options logic
62
+ myOptionsLogic();
63
+ }
64
+ ```
65
+
66
+ ## Reference
67
+
68
+ ### PardusOptions Object
69
+ `PardusOptions`
70
+ #### Creation
71
+ This is a static object that you should not construct, and as such the constructor is not documented here. Including the library in your script will automatically initialise it on the relevant options page.
72
+ #### Methods
73
+
74
+ ##### version
75
+ Returns the version of the library.
76
+ ```javascript
77
+ PardusOptions.version();
78
+ ```
79
+ ##### addTab
80
+ Creates a new tab and returns an object allowing manipulation of the content of the tab. Recommended usage is one tab per script.
81
+ ```javascript
82
+ PardusOptions.addTab({
83
+ id,
84
+ heading,
85
+ saveFunction = PardusOptionsUtility.defaultSaveFunction,
86
+ getFunction = PardusOptionsUtility.defaultGetFunction,
87
+ });
88
+ ```
89
+ **id** [*Required*]: An identification string with no spaces that must be unique across all scripts using this library.
90
+ **heading** [*Required*]: The heading of the tab. You should ensure this string is not too long to break the formatting.
91
+ **saveFunction** [*Optional*]: A reference to a function that can save a persistent value for you. This is automatically set to the script's `GM_setValue` method.
92
+ **getFunction** [*Optional*]: A reference to a function that can retrieve a persistent value for you. This is automatically set to the script's `GM_getValue` method.
93
+
94
+ Returns an object of type OptionsContent, allowing manipulation of the content within the tab's content area.
95
+
96
+ Example:
97
+ ```javascript
98
+ const myTab = PardusOptions.addTab({
99
+ id: 'my-scripts-tab',
100
+ heading: 'My Script',
101
+ saveFunction: GM_setValue,
102
+ getFunction: GM_getValue,
103
+ });
104
+ ```
105
+
106
+ ### Class OptionsContent
107
+ Represents all the content within a single tab, allowing for easy creation of OptionsBoxes.
108
+ #### Creation
109
+ You should use the `PardusOptions.addTab()` method to obtain an OptionsContent object, and as such the constructor is not documented here.
110
+ #### Methods
111
+
112
+ ##### addBox
113
+ Creates a new box in the contents area of the tab, and returns an object allowing manipulation of the content of the box. Recommended usage is one box per group of related options. This box will be placed on either the left or right side of the screen depending on the length of all the other boxes. If you wish to control the placing, see `addBoxLeft` and `addBoxRight`.
114
+ ```javascript
115
+ OptionsContent.addBox({
116
+ heading,
117
+ description = '',
118
+ imageLeft = '',
119
+ imageRight = '',
120
+ premium = false,
121
+ saveFunction = this.saveFunction,
122
+ getFunction = this.getFunction,
123
+ });
124
+ ```
125
+ **heading** [*Required*]: The heading of the box.
126
+ **description** [*Optional*]: The description text for the box, to be displayed under the heading.
127
+ **imageLeft** [*Optional*]: The src value of an image to appear to the left of the description.
128
+ **imageRight** [*Optional*]: The src value of an image to appear to the right of the description.
129
+ **premium** [*Optional*]: A boolean value on whether to style the box with the premium styling or not. Useful for separating options relating to features exclusive for premium members.
130
+ **saveFunction** [*Optional*]: A reference to a function that can save a persistent value for you. Will inherit the save function of the tab.
131
+ **getFunction** [*Optional*]: A reference to a function that can retrieve a persistent value for you. Will inherit the get function of the tab.
132
+
133
+ Returns an object of type OptionsBox, allowing creation of options within the box.
134
+
135
+ Example:
136
+ ```javascript
137
+ const myBox = myTab.addBox({
138
+ heading: 'Main Options',
139
+ description: 'These are the main options for my script.',
140
+ });
141
+ ```
142
+
143
+ ##### addBoxLeft
144
+ Creates a new box in the left column of the contents area of the tab, and returns an object allowing manipulation of the content of the box. Recommended usage is one box per group of related options. This box will be placed on the left side of the screen..
145
+ ```javascript
146
+ OptionsContent.addBoxLeft({
147
+ heading,
148
+ description = '',
149
+ imageLeft = '',
150
+ imageRight = '',
151
+ premium = false,
152
+ saveFunction = this.saveFunction,
153
+ getFunction = this.getFunction,
154
+ });
155
+ ```
156
+ **heading** [*Required*]: The heading of the box.
157
+ **description** [*Optional*]: The description text for the box, to be displayed under the heading.
158
+ **imageLeft** [*Optional*]: The src value of an image to appear to the left of the description.
159
+ **imageRight** [*Optional*]: The src value of an image to appear to the right of the description.
160
+ **premium** [*Optional*]: A boolean value on whether to style the box with the premium styling or not. Useful for separating options relating to features exclusive for premium members.
161
+ **saveFunction** [*Optional*]: A reference to a function that can save a persistent value for you. Will inherit the save function of the tab.
162
+ **getFunction** [*Optional*]: A reference to a function that can retrieve a persistent value for you. Will inherit the get function of the tab.
163
+
164
+ Returns an object of type OptionsBox, allowing creation of options within the box.
165
+
166
+ Example:
167
+ ```javascript
168
+ const myBox = myTab.addBoxLeft({
169
+ heading: 'Main Options',
170
+ description: 'These are the main options for my script.',
171
+ });
172
+ ```
173
+
174
+ ##### addBoxRight
175
+ Creates a new box in the right column of the contents area of the tab, and returns an object allowing manipulation of the content of the box. Recommended usage is one box per group of related options. This box will be placed on the right side of the screen..
176
+ ```javascript
177
+ OptionsContent.addBoxLeft({
178
+ heading,
179
+ description = '',
180
+ imageLeft = '',
181
+ imageRight = '',
182
+ premium = false,
183
+ saveFunction = this.saveFunction,
184
+ getFunction = this.getFunction,
185
+ });
186
+ ```
187
+ **heading** [*Required*]: The heading of the box.
188
+ **description** [*Optional*]: The description text for the box, to be displayed under the heading.
189
+ **imageLeft** [*Optional*]: The src value of an image to appear to the left of the description.
190
+ **imageRight** [*Optional*]: The src value of an image to appear to the right of the description.
191
+ **premium** [*Optional*]: A boolean value on whether to style the box with the premium styling or not. Useful for separating options relating to features exclusive for premium members.
192
+ **saveFunction** [*Optional*]: A reference to a function that can save a persistent value for you. Will inherit the save function of the tab.
193
+ **getFunction** [*Optional*]: A reference to a function that can retrieve a persistent value for you. Will inherit the get function of the tab.
194
+
195
+ Returns an object of type OptionsBox, allowing creation of options within the box.
196
+
197
+ Example:
198
+ ```javascript
199
+ const myBox = myTab.addBoxLeft({
200
+ heading: 'Main Options',
201
+ description: 'These are the main options for my script.',
202
+ });
203
+ ```
204
+
205
+
206
+
207
+
208
+ ### Class OptionsBox
209
+ Represents a box that contains options.
210
+ #### Creation
211
+ You should use the `OptionsContent.addBox()` method to obtain an OptionsBox object, and as such the constructor is not documented here.
212
+ #### Methods
213
+
214
+ ##### addBooleanOption
215
+ Creates a checkbox within the options box, and binds its value to a variable that can be saved persistently using the `saveFunction`.
216
+ ```javascript
217
+ OptionsBox.addBooleanOption({
218
+ variable,
219
+ description,
220
+ defaultValue = false,
221
+ customSaveFunction = this.saveFunction,
222
+ customGetFunction = this.getFunction,
223
+ });
224
+ ```
225
+ **variable** [*Required*]: The variable to bind the boolean value to. This will be translated into `${universe}-${variable}` when passed into the save function, to ensure uniqueness across all the universes.
226
+ **description** [*Required*]: A small amount of text describing what the option is for.
227
+ **defaultValue** [*Optional*]: The default value to set. It is recommended to always define a default value.
228
+ **saveFunction** [*Optional*]: A reference to a function that can save a persistent value for you. Will inherit the save function of the OptionsContent.
229
+ **getFunction** [*Optional*]: A reference to a function that can retrieve a persistent value for you. Will inherit the get function of the OptionsContent.
230
+
231
+ Returns an object of type BooleanOption, although this isn't used for anything.
232
+
233
+ Example:
234
+ ```javascript
235
+ myBox.addBooleanOption({
236
+ variable: 'enable_super_cool_feature',
237
+ description: 'Enable the super cool feature',
238
+ defaultValue: true,
239
+ });
240
+ ```
241
+
242
+
243
+ ##### addNumericOption
244
+ Creates a numeric field within the options box, and binds its value to a variable that can be saved persistently using the `saveFunction`.
245
+ ```javascript
246
+ OptionsBox.addNumericOption({
247
+ variable,
248
+ description,
249
+ defaultValue = 0,
250
+ min = 0,
251
+ max = 0,
252
+ step = 1,
253
+ saveFunction = this.saveFunction,
254
+ getFunction = this.getFunction,
255
+ });
256
+ ```
257
+ **variable** [*Required*]: The variable to bind the boolean value to. This will be translated into `${universe}-${variable}` when passed into the save function, to ensure uniqueness across all the universes.
258
+ **description** [*Required*]: A small amount of text describing what the option is for.
259
+ **defaultValue** [*Optional*]: The default value to set. It is recommended to always define a default value.
260
+ **min** [*Optional*]: The minimum value the field may have.
261
+ **max** [*Optional*]: The maximum value the field may have.
262
+ **step** [*Optional*]: The increments between values.
263
+ **saveFunction** [*Optional*]: A reference to a function that can save a persistent value for you. Will inherit the save function of the OptionsContent.
264
+ **getFunction** [*Optional*]: A reference to a function that can retrieve a persistent value for you. Will inherit the get function of the OptionsContent.
265
+
266
+ Returns an object of type NumericOption, although this isn't used for anything.
267
+
268
+ Example:
269
+ ```javascript
270
+ myBox.addNumericOption({
271
+ variable: 'amount_of_power',
272
+ description: 'Amount of power to use',
273
+ defaultValue: 50,
274
+ min: 1,
275
+ max: 100,
276
+ });
277
+ ```
278
+
279
+
280
+ ##### addSelectOption
281
+ Creates a dropdown selection field within the options box, and binds its value to a variable that can be saved persistently using the `saveFunction`.
282
+ ```javascript
283
+ OptionsBox.addSelectOption({
284
+ variable,
285
+ description,
286
+ options = [],
287
+ defaultValue = null,
288
+ saveFunction = this.saveFunction,
289
+ getFunction = this.getFunction,
290
+ });
291
+ ```
292
+ **variable** [*Required*]: The variable to bind the boolean value to. This will be translated into `${universe}-${variable}` when passed into the save function, to ensure uniqueness across all the universes.
293
+ **description** [*Required*]: A small amount of text describing what the option is for.
294
+ **options** [*Optional*]: An array of dropdown options to give. The array must be in the format `[{value: 'value-to-save', text: 'value to display to the user'}, ...]`. Additionally, one element may contain a `default: true` field instead of passing in a default value.
295
+ **defaultValue** [*Optional*]: The default value to set. It is recommended to always define a default value. This should correspond to one of the `value` fields in the `options` parameter.
296
+ **saveFunction** [*Optional*]: A reference to a function that can save a persistent value for you. Will inherit the save function of the OptionsContent.
297
+ **getFunction** [*Optional*]: A reference to a function that can retrieve a persistent value for you. Will inherit the get function of the OptionsContent.
298
+
299
+ Returns an object of type NumericOption, although this isn't used for anything.
300
+
301
+ Example:
302
+ ```javascript
303
+ myBox.addSelectOption({
304
+ variable: 'attack_style',
305
+ description: 'Attack style to use',
306
+ options: [
307
+ {
308
+ value: 'offensive',
309
+ text: 'Offensive'
310
+ },
311
+ {
312
+ value: 'balanced',
313
+ text: 'Balanced',
314
+ default: true
315
+ },
316
+ {
317
+ value: 'defensive',
318
+ text: 'Defensive'
319
+ },
320
+ ],
321
+ });
322
+ ```
323
+
@@ -0,0 +1,38 @@
1
+ import { defineConfig } from "eslint/config";
2
+ import globals from "globals";
3
+ import stylistic from "@stylistic/eslint-plugin";
4
+
5
+ export default defineConfig([
6
+ {
7
+ languageOptions: {
8
+ globals: {
9
+ ...globals.browser,
10
+ ...globals.greasemonkey,
11
+ Atomics: "readonly",
12
+ SharedArrayBuffer: "readonly",
13
+ },
14
+ ecmaVersion: "latest",
15
+ sourceType: "module",
16
+ },
17
+ plugins: {
18
+ "@stylistic": stylistic,
19
+ },
20
+ files: ["**/*.js"],
21
+ ignores: ["dist/**"],
22
+ rules: {
23
+ "@stylistic/brace-style": ["error", "1tbs"],
24
+ "semi": "error",
25
+ "prefer-const": "error",
26
+ "indent": ["error", 4, { SwitchCase: 1 }],
27
+ "curly": ["error", "all"],
28
+ "max-len": "off",
29
+ "wrap-iife": [2, "inside"],
30
+ "no-console": "off",
31
+ "max-classes-per-file": "off",
32
+ "spaced-comment": "off",
33
+ "class-methods-use-this": "off",
34
+ "no-restricted-syntax": "off",
35
+ "no-use-before-define": "off",
36
+ },
37
+ },
38
+ ]);
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "pardus-options-library",
3
+ "version": "2.7.0",
4
+ "description": "The Pardus Options Library is a script designed to add useful and easy ways to interact with the Options page within other scripts related to the online game Pardus (https://pardus.at).",
5
+ "main": "src/index.js",
6
+ "devDependencies": {
7
+ "@stylistic/eslint-plugin": "^5.9.0",
8
+ "eslint": "^10.0.0",
9
+ "globals": "^16.1.0",
10
+ "jsdoc": "^4.0.2",
11
+ "webpack": "^5.48.0",
12
+ "webpack-cli": "^5.1.4"
13
+ },
14
+ "scripts": {
15
+ "test": "echo \"Error: no test specified\" && exit 1",
16
+ "lint": "eslint src",
17
+ "lint-fix": "eslint src --fix",
18
+ "gen-docs": "./node_modules/.bin/jsdoc src --destination docs --recurse",
19
+ "build": "npx webpack-cli --config webpack.config.cjs"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Tro95/Pardus-Options-Library.git"
24
+ },
25
+ "type": "module",
26
+ "author": "",
27
+ "license": "ISC",
28
+ "bugs": {
29
+ "url": "https://github.com/Tro95/Pardus-Options-Library/issues"
30
+ },
31
+ "homepage": "https://github.com/Tro95/Pardus-Options-Library#readme"
32
+ }
@@ -0,0 +1,116 @@
1
+ import DisableableHtmlElement from '../disableable-html-element.js';
2
+
3
+ export default class AbstractButton extends DisableableHtmlElement {
4
+ constructor({
5
+ id,
6
+ premium = false,
7
+ disabled = false,
8
+ styleExtra = '',
9
+ actionText = '',
10
+ actionPerformedText = '',
11
+ }) {
12
+ super({
13
+ id,
14
+ disabled,
15
+ });
16
+
17
+ this.premium = premium;
18
+
19
+ if (this.premium) {
20
+ this.colour = '#FFCC11';
21
+ } else {
22
+ this.colour = '#D0D1D9';
23
+ }
24
+
25
+ this.backgroundColour = '#00001C';
26
+
27
+ if (this.disabled) {
28
+ this.colour = '#B5B5B5';
29
+ this.backgroundColour = '#CCCCCC';
30
+ }
31
+
32
+ this.styleExtra = styleExtra;
33
+ this.style = `color: ${this.colour};background-color: ${this.backgroundColour};${this.styleExtra}`;
34
+
35
+ this.actionText = actionText;
36
+ this.actionPerformedText = actionPerformedText;
37
+ }
38
+
39
+ toString() {
40
+ return `<input value="${this.actionText}" id="${this.id}" type="button" style="${this.style}" ${this.disabled ? 'disabled' : ''}>`;
41
+ }
42
+
43
+ /**
44
+ * Add an event listener to the element
45
+ * @function HtmlElement#addEventListener
46
+ * @param {function} listener Listener to call when the event fires
47
+ */
48
+ addClickListener(listener, opts = false) {
49
+ if (this.getElement()) {
50
+ this.getElement().addEventListener('click', listener, opts);
51
+ }
52
+
53
+ if (opts && Object.hasOwn(opts, 'ephemeral') && opts.ephemeral) {
54
+ return;
55
+ }
56
+
57
+ this.addAfterRefreshHook(() => {
58
+ if (this.getElement()) {
59
+ this.getElement().addEventListener('click', listener, opts);
60
+ }
61
+ });
62
+ }
63
+
64
+ setActionText(actionText = '', actionPerformedText = '') {
65
+ this.actionText = actionText;
66
+ this.actionPerformedText = actionPerformedText;
67
+ this.refreshElement();
68
+ }
69
+
70
+ displayClicked() {
71
+ this.getElement().setAttribute('disabled', 'true');
72
+ this.getElement().value = this.actionPerformedText;
73
+ this.getElement().setAttribute('style', 'color:green;background-color:silver');
74
+ setTimeout(() => {
75
+ this.getElement().removeAttribute('disabled');
76
+ this.getElement().value = this.actionText;
77
+ if (this.premium) {
78
+ this.getElement().setAttribute('style', 'color:#FFCC11');
79
+ } else {
80
+ this.getElement().removeAttribute('style');
81
+ }
82
+ }, 2000);
83
+ }
84
+
85
+ setDisabled(disabled = false) {
86
+ this.disabled = disabled;
87
+ if (this.disabled) {
88
+ this.colour = '#B5B5B5';
89
+ this.backgroundColour = '#CCCCCC';
90
+ } else {
91
+ if (this.premium) {
92
+ this.colour = '#FFCC11';
93
+ } else {
94
+ this.colour = '#D0D1D9';
95
+ }
96
+ this.backgroundColour = '#00001C';
97
+ }
98
+ this.style = `color: ${this.colour};background-color: ${this.backgroundColour};${this.styleExtra}`;
99
+ }
100
+
101
+ disable() {
102
+ this.setDisabled(true);
103
+ if (this.getElement()) {
104
+ this.getElement().setAttribute('disabled', 'true');
105
+ this.getElement().setAttribute('style', this.style);
106
+ }
107
+ }
108
+
109
+ enable() {
110
+ this.setDisabled(false);
111
+ if (this.getElement()) {
112
+ this.getElement().removeAttribute('disabled');
113
+ this.getElement().setAttribute('style', this.style);
114
+ }
115
+ }
116
+ }
@@ -0,0 +1,145 @@
1
+ import AbstractButton from './abstract-button.js';
2
+
3
+ export default class AbstractToggleButton extends AbstractButton {
4
+ constructor({
5
+ id,
6
+ premium = false,
7
+ disabled = false,
8
+ styleExtra = '',
9
+ actionText = '',
10
+ actionPerformedText = '',
11
+ toggleText = '',
12
+ togglePerformedText = '',
13
+ toggled = false,
14
+ }) {
15
+ super({
16
+ id,
17
+ premium,
18
+ disabled,
19
+ styleExtra,
20
+ actionText,
21
+ actionPerformedText,
22
+ });
23
+
24
+ this.toggled = toggled;
25
+
26
+ this.defaultText = actionText;
27
+ this.defaultPerformedText = actionPerformedText;
28
+ this.toggleText = toggleText;
29
+ this.togglePerformedText = togglePerformedText;
30
+
31
+ if (this.toggled) {
32
+ this.actionText = this.toggleText;
33
+ this.actionPerformedText = this.togglePerformedText;
34
+ }
35
+ }
36
+
37
+ toggle() {
38
+ this.toggled = !this.toggled;
39
+
40
+ if (this.toggled) {
41
+ this.actionText = this.toggleText;
42
+ this.actionPerformedText = this.togglePerformedText;
43
+ } else {
44
+ this.actionText = this.defaultText;
45
+ this.actionPerformedText = this.defaultPerformedText;
46
+ }
47
+
48
+ this.refreshElement();
49
+ }
50
+
51
+ toString() {
52
+ return `<input value="${this.actionText}" id="${this.id}" type="button" style="${this.style}" ${this.disabled ? 'disabled' : ''}>`;
53
+ }
54
+
55
+ displayClicked() {
56
+ this.getElement().setAttribute('disabled', 'true');
57
+ this.getElement().value = this.actionPerformedText;
58
+ this.getElement().setAttribute('style', 'color:green;background-color:silver');
59
+ setTimeout(() => {
60
+ this.getElement().removeAttribute('disabled');
61
+ this.getElement().value = this.actionText;
62
+ if (this.premium) {
63
+ this.getElement().setAttribute('style', 'color:#FFCC11');
64
+ } else {
65
+ this.getElement().removeAttribute('style');
66
+ }
67
+ }, 2000);
68
+ }
69
+
70
+ /**
71
+ * Add an event listener to the element
72
+ * @function HtmlElement#addEventListener
73
+ * @param {string} eventName Name of the event to listen for
74
+ * @param {function} listener Listener to call when the event fires
75
+ */
76
+ addClickListener(listener, opts = false) {
77
+ if (this.getElement() && !this.toggled) {
78
+ this.getElement().addEventListener('click', listener, opts);
79
+ }
80
+
81
+ if (opts && Object.hasOwn(opts, 'ephemeral') && opts.ephemeral) {
82
+ return;
83
+ }
84
+
85
+ this.addAfterRefreshHook(() => {
86
+ if (this.getElement() && !this.toggled) {
87
+ this.getElement().addEventListener('click', listener, opts);
88
+ }
89
+ });
90
+ }
91
+
92
+ /**
93
+ * Add an event listener to the element
94
+ * @function HtmlElement#addEventListener
95
+ * @param {string} eventName Name of the event to listen for
96
+ * @param {function} listener Listener to call when the event fires
97
+ */
98
+ addToggleClickListener(listener, opts = false) {
99
+ if (this.getElement() && this.toggled) {
100
+ this.getElement().addEventListener('click', listener, opts);
101
+ }
102
+
103
+ if (opts && Object.hasOwn(opts, 'ephemeral') && opts.ephemeral) {
104
+ return;
105
+ }
106
+
107
+ this.addAfterRefreshHook(() => {
108
+ if (this.getElement() && this.toggled) {
109
+ this.getElement().addEventListener('click', listener, opts);
110
+ }
111
+ });
112
+ }
113
+
114
+ setDisabled(disabled = false) {
115
+ this.disabled = disabled;
116
+ if (this.disabled) {
117
+ this.colour = '#B5B5B5';
118
+ this.backgroundColour = '#CCCCCC';
119
+ } else {
120
+ if (this.premium) {
121
+ this.colour = '#FFCC11';
122
+ } else {
123
+ this.colour = '#D0D1D9';
124
+ }
125
+ this.backgroundColour = '#00001C';
126
+ }
127
+ this.style = `color: ${this.colour};background-color: ${this.backgroundColour};${this.styleExtra}`;
128
+ }
129
+
130
+ disable() {
131
+ this.setDisabled(true);
132
+ if (this.getElement()) {
133
+ this.getElement().setAttribute('disabled', 'true');
134
+ this.getElement().setAttribute('style', this.style);
135
+ }
136
+ }
137
+
138
+ enable() {
139
+ this.setDisabled(false);
140
+ if (this.getElement()) {
141
+ this.getElement().removeAttribute('disabled');
142
+ this.getElement().setAttribute('style', this.style);
143
+ }
144
+ }
145
+ }
@@ -0,0 +1,22 @@
1
+ import HtmlElement from './html-element.js';
2
+
3
+ export default class ContentsArea extends HtmlElement {
4
+ constructor({
5
+ id,
6
+ }) {
7
+ super(id);
8
+ }
9
+
10
+ addContent({
11
+ content,
12
+ }) {
13
+ this.appendChild(document.createElement('div').appendChild(content.toElement()));
14
+ content.afterRefreshElement({
15
+ maintainRefreshStatus: true,
16
+ });
17
+ }
18
+
19
+ toString() {
20
+ return `<tr id="${this.id}" cellspacing="0" cellpadding="0" border="0"></tr>`;
21
+ }
22
+ }