@vacantthinker/firefox-addon-framework-easy 2026.526.1702 → 2026.526.2259
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.
- package/package.json +1 -1
- package/src/generate.js +51 -2
- package/src/serviceFetch.js +5 -1
package/package.json
CHANGED
package/src/generate.js
CHANGED
|
@@ -11,7 +11,10 @@ export function generateHtmlByUserSettings(
|
|
|
11
11
|
userSettings,
|
|
12
12
|
radioItemClickCallback,
|
|
13
13
|
) {
|
|
14
|
-
|
|
14
|
+
// Keeps track of all generated fieldsets by their storageKey
|
|
15
|
+
const elementsMap = {};
|
|
16
|
+
|
|
17
|
+
const fieldsets = Object.keys(userSettings).map((storageKey) => {
|
|
15
18
|
const storageValue = userSettings[storageKey];
|
|
16
19
|
const type = storageValue.type || 'text'; // Default to text if type is not specified
|
|
17
20
|
|
|
@@ -21,6 +24,9 @@ export function generateHtmlByUserSettings(
|
|
|
21
24
|
eleTitle.textContent = storageKey;
|
|
22
25
|
eleWrap.append(eleTitle);
|
|
23
26
|
|
|
27
|
+
// Save a reference to the wrapper element for visibility switching
|
|
28
|
+
elementsMap[storageKey] = eleWrap;
|
|
29
|
+
|
|
24
30
|
// --- CONDITION 1: CHECKBOX & RADIO ---
|
|
25
31
|
if (type === 'checkbox' || type === 'radio') {
|
|
26
32
|
const options = storageValue.options || [];
|
|
@@ -39,6 +45,9 @@ export function generateHtmlByUserSettings(
|
|
|
39
45
|
const initialArray = Array.from(v || storageValue.selected || []);
|
|
40
46
|
const set = new Set(initialArray);
|
|
41
47
|
eleInput.checked = set.has(option);
|
|
48
|
+
|
|
49
|
+
// Initial visibility evaluation
|
|
50
|
+
triggerVisibility(storageKey, initialArray);
|
|
42
51
|
});
|
|
43
52
|
|
|
44
53
|
eleInput.addEventListener('change', async () => {
|
|
@@ -54,6 +63,9 @@ export function generateHtmlByUserSettings(
|
|
|
54
63
|
const valueNew = Array.from(set);
|
|
55
64
|
console.info(`k=${storageKey} option=${option} eleInput.checked=${eleInput.checked} valueNew=${valueNew}`);
|
|
56
65
|
await stoOpSet(storageKey, valueNew);
|
|
66
|
+
|
|
67
|
+
// Dynamic visibility update
|
|
68
|
+
triggerVisibility(storageKey, valueNew);
|
|
57
69
|
});
|
|
58
70
|
}
|
|
59
71
|
else if (type === 'radio') {
|
|
@@ -62,6 +74,9 @@ export function generateHtmlByUserSettings(
|
|
|
62
74
|
if (option === currentSelected) {
|
|
63
75
|
eleInput.checked = true;
|
|
64
76
|
}
|
|
77
|
+
|
|
78
|
+
// Initial visibility evaluation
|
|
79
|
+
triggerVisibility(storageKey, currentSelected);
|
|
65
80
|
});
|
|
66
81
|
|
|
67
82
|
eleLabel.onclick = function () {
|
|
@@ -70,6 +85,9 @@ export function generateHtmlByUserSettings(
|
|
|
70
85
|
if (typeof radioItemClickCallback === 'function') {
|
|
71
86
|
radioItemClickCallback(storageKey, option);
|
|
72
87
|
}
|
|
88
|
+
|
|
89
|
+
// Dynamic visibility update
|
|
90
|
+
triggerVisibility(storageKey, option);
|
|
73
91
|
});
|
|
74
92
|
};
|
|
75
93
|
}
|
|
@@ -89,11 +107,17 @@ export function generateHtmlByUserSettings(
|
|
|
89
107
|
let currentStatus = (v !== undefined && v !== null) ? (v === true || v === 'true') : storageValue.selected;
|
|
90
108
|
eleButton.textContent = String(currentStatus);
|
|
91
109
|
|
|
110
|
+
// Initial visibility evaluation
|
|
111
|
+
triggerVisibility(storageKey, currentStatus);
|
|
112
|
+
|
|
92
113
|
eleButton.addEventListener('click', async () => {
|
|
93
114
|
currentStatus = !currentStatus; // Toggle state
|
|
94
115
|
eleButton.textContent = String(currentStatus);
|
|
95
116
|
console.info(`k=${storageKey} toggled to=${currentStatus}`);
|
|
96
117
|
await stoOpSet(storageKey, currentStatus);
|
|
118
|
+
|
|
119
|
+
// Dynamic visibility update
|
|
120
|
+
triggerVisibility(storageKey, currentStatus);
|
|
97
121
|
});
|
|
98
122
|
});
|
|
99
123
|
|
|
@@ -109,6 +133,9 @@ export function generateHtmlByUserSettings(
|
|
|
109
133
|
stoOpGet(storageKey).then((v) => {
|
|
110
134
|
const currentVal = (v !== undefined && v !== null) ? v : storageValue.selected;
|
|
111
135
|
eleInput.value = currentVal;
|
|
136
|
+
|
|
137
|
+
// Initial visibility evaluation
|
|
138
|
+
triggerVisibility(storageKey, currentVal);
|
|
112
139
|
});
|
|
113
140
|
|
|
114
141
|
// Updates storage on every keystroke/change execution
|
|
@@ -118,6 +145,9 @@ export function generateHtmlByUserSettings(
|
|
|
118
145
|
|
|
119
146
|
console.info(`k=${storageKey} value changed to=${finalizedValue}`);
|
|
120
147
|
await stoOpSet(storageKey, finalizedValue);
|
|
148
|
+
|
|
149
|
+
// Dynamic visibility update
|
|
150
|
+
triggerVisibility(storageKey, finalizedValue);
|
|
121
151
|
});
|
|
122
152
|
|
|
123
153
|
eleWrap.append(eleInput);
|
|
@@ -125,4 +155,23 @@ export function generateHtmlByUserSettings(
|
|
|
125
155
|
|
|
126
156
|
return eleWrap;
|
|
127
157
|
});
|
|
128
|
-
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Evaluates the visibility rules for a given source key based on its current value.
|
|
161
|
+
*/
|
|
162
|
+
function triggerVisibility(sourceKey, currentValue) {
|
|
163
|
+
const config = userSettings[sourceKey];
|
|
164
|
+
if (config && config.visibilityControl) {
|
|
165
|
+
const { targetField, expectedValue } = config.visibilityControl;
|
|
166
|
+
const targetElement = elementsMap[targetField];
|
|
167
|
+
|
|
168
|
+
if (targetElement) {
|
|
169
|
+
// String conversion guarantees type safety (e.g., matching boolean true against string "true")
|
|
170
|
+
const shouldBeVisible = String(currentValue) === String(expectedValue);
|
|
171
|
+
targetElement.style.display = shouldBeVisible ? '' : 'none';
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return fieldsets;
|
|
177
|
+
}
|
package/src/serviceFetch.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {browserNotificationCreate} from './browserNotification.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
*
|
|
3
5
|
* @param serverUrl{string}
|
|
@@ -38,7 +40,7 @@ export async function servicePostJson(
|
|
|
38
40
|
* rpcsecret:string,
|
|
39
41
|
* rpcport:string
|
|
40
42
|
* }}
|
|
41
|
-
* @returns {Promise<Response>}
|
|
43
|
+
* @returns {Promise<Response|null>}
|
|
42
44
|
*/
|
|
43
45
|
export async function serviceSendDataToLocalAria2(message) {
|
|
44
46
|
let {downlink, filename, rpcsecret, rpcport} = message;
|
|
@@ -74,7 +76,9 @@ export async function serviceSendDataToLocalAria2(message) {
|
|
|
74
76
|
|
|
75
77
|
return response;
|
|
76
78
|
} catch (e) {
|
|
79
|
+
await browserNotificationCreate(e)
|
|
77
80
|
console.error(e);
|
|
81
|
+
return null;
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
}
|