@vacantthinker/firefox-addon-framework-easy 2026.5.2205 → 2026.5.2207

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/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  export * from './src/baseService.js'
2
2
  export * from './src/baseRuntimeSetup.js'
3
+
4
+
3
5
  export * from './src/baseOp.js'
6
+ export * from './src/baseOpTab.js'
7
+ export * from './src/baseOpStorage.js'
8
+
9
+
4
10
  export * from './src/baseORM.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vacantthinker/firefox-addon-framework-easy",
3
- "version": "2026.5.2205",
3
+ "version": "2026.5.2207",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -8,6 +8,8 @@
8
8
  },
9
9
  "scripts": {
10
10
  "npm_install": "npm install",
11
+ "git_acp": "git add . && git commit -m 'update' && git push",
12
+ "npm_publish": "npm publish",
11
13
  "webpack": "webpack",
12
14
  "webpack_pack": "webpack && node _zipit.js"
13
15
  },
package/src/baseORM.js CHANGED
@@ -1,119 +1,228 @@
1
- import {
2
- stoOpCheck,
3
- stoOpGet,
4
- stoOpQuery_startsWith,
5
- stoOpRem,
6
- stoOpSet
7
- } from "./baseOp.js";
1
+ import {stoOpCheck, stoOpGet, stoOpQuery_startsWith, stoOpRem, stoOpSet} from "./baseOp.js";
2
+
8
3
 
9
4
  /**
10
5
  * eg:
11
6
  *
12
- * "domain www.abcdefg.com":{
7
+ * "domain ://abcdefg.com":{
13
8
  * "keyAAA": "valueBBB"
14
9
  * }
15
- *
16
- * @returns {{getALLDomainKey: function(): Promise<string[]>, getALLDomainMap: function(): Promise<{domainList: *, domainKeyValueMap: {}}>, getDomain: function(string): Promise<{}>, updateDomainValueByOneKeyValue: function(string, string, string): Promise<{}>, clearThisDomain: function(*): Promise<{}>}}
17
10
  */
18
- export function baseORM() {
11
+ export class BaseORM {
12
+ // Private class fields for encapsulation
13
+ #keyPrefix = `domain `;
14
+ #domainDefaultValue = {};
15
+
16
+ // Private helper method to generate the prefix key
17
+ #domainKey(k) {
18
+ return `${this.#keyPrefix}${k}`;
19
+ }
20
+
21
+ /**
22
+ * check domain exists, return true/false
23
+ * @param {string} domain
24
+ * @return {Promise<boolean>}
25
+ */
26
+ async #checkDomain(domain) {
27
+ return await stoOpCheck(this.#domainKey(domain));
28
+ }
29
+
30
+ /**
31
+ * @param {string} domain
32
+ * @return {Promise<void>}
33
+ */
34
+ async #addDomain(domain) {
35
+ await stoOpSet(this.#domainKey(domain), this.#domainDefaultValue);
36
+ }
37
+
38
+ /**
39
+ * @param {string} domain
40
+ * @return {Promise<void>}
41
+ */
42
+ async #removeDomain(domain) {
43
+ await stoOpRem(this.#domainKey(domain));
44
+ }
45
+
46
+ /**
47
+ * @param {string} domain
48
+ * @param {*} valueNew
49
+ * @return {Promise<void>}
50
+ */
51
+ async #updateDomain(domain, valueNew) {
52
+ await stoOpSet(this.#domainKey(domain), valueNew);
53
+ }
19
54
 
20
- let keyPrefix = `domain `;
21
- const domainKey = (k) => `${keyPrefix}${k}`;
22
- const domainDefaultValue = {};
23
-
24
- /**
25
- * check domain exists, return true/false
26
- * @param domain{string}
27
- * @return {Promise<boolean>}
28
- */
29
- async function checkDomain(domain) {
30
- return await stoOpCheck(domainKey(domain));
31
- }
32
-
33
- /**
34
- * @param domain{string}
35
- * @return {Promise<void>}
36
- */
37
- async function addDomain(domain) {
38
- await stoOpSet(domainKey(domain), domainDefaultValue);
39
- }
40
-
41
- /**
42
- * @param domain{string}
43
- * @return {Promise<void>}
44
- */
45
- async function removeDomain(domain) {
46
- await stoOpRem(domainKey(domain));
47
- }
48
-
49
- /**
50
- * @param domain{string}
51
- * @param valueNew
52
- * @return {Promise<void>}
53
- */
54
- async function updateDomain(domain, valueNew) {
55
- await stoOpSet(domainKey(domain), valueNew);
56
- }
57
-
58
- return {
59
55
  /**
60
56
  * eg: ['a.com', 'b.com', 'c.com']
61
57
  * @returns {Promise<string[]>}
62
58
  */
63
- getALLDomainKey: async function () {
64
- // stoOpQueryByPrefix
65
- let strings = await stoOpQuery_startsWith(keyPrefix);
66
- return strings.map(v => v.replaceAll(keyPrefix, ''));
67
- },
68
- getALLDomainMap: async function () {
69
- let domainList = await this.getALLDomainKey();
70
-
71
- // todo use for-loop not the reduce()!
72
- const domainKeyValueMap = {}
73
- for (let domain of domainList) {
74
- domainKeyValueMap[domain] = await this.getDomain(domain)
75
- }
76
-
77
- return {domainList, domainKeyValueMap};
78
- },
59
+ async getALLDomainKey() {
60
+ // stoOpQueryByPrefix
61
+ let strings = await stoOpQuery_startsWith(this.#keyPrefix);
62
+ return strings.map(v => v.replaceAll(this.#keyPrefix, ''));
63
+ }
79
64
 
80
65
  /**
81
- *
82
- * @param {string}domain
66
+ * @returns {Promise<{domainList: string[], domainKeyValueMap: {}}>}
67
+ */
68
+ async getALLDomainMap() {
69
+ let domainList = await this.getALLDomainKey();
70
+
71
+ const domainKeyValueMap = {};
72
+ for (let domain of domainList) {
73
+ domainKeyValueMap[domain] = await this.getDomain(domain);
74
+ }
75
+
76
+ return {domainList, domainKeyValueMap};
77
+ }
78
+
79
+ /**
80
+ * @param {string} domain
83
81
  * @returns {Promise<{}>}
84
82
  */
85
- getDomain: async function (domain) {
86
- if (!await checkDomain(domain)) {
87
- await addDomain(domain);
88
- }
89
- return await stoOpGet(domainKey(domain));
90
- },
83
+ async getDomain(domain) {
84
+ if (!(await this.#checkDomain(domain))) {
85
+ await this.#addDomain(domain);
86
+ }
87
+ return await stoOpGet(this.#domainKey(domain));
88
+ }
91
89
 
92
90
  /**
93
91
  * {a:a1} => {a:a222}
94
- * @param {string}domain 'xxx.xxxxx.xxx'
95
- * @param{string}key
96
- * @param {string}valueToUpdate
92
+ * @param {string} domain 'xxx.xxxxx.xxx'
93
+ * @param {string} key
94
+ * @param {string} valueToUpdate
97
95
  * @return {Promise<{}>}
98
96
  */
99
- updateDomainValueByOneKeyValue: async function (domain, key ,valueToUpdate) {
100
- if (!await checkDomain(domain)) {
101
- await addDomain(domain);
102
- }
103
- let domainValueGet = await this.getDomain(domain);
104
- domainValueGet[key]=valueToUpdate;
105
- await updateDomain(domain, domainValueGet);
106
- return (await this.getDomain(domain));
107
- },
97
+ async updateDomainValueByOneKeyValue(domain, key, valueToUpdate) {
98
+ if (!(await this.#checkDomain(domain))) {
99
+ await this.#addDomain(domain);
100
+ }
101
+ let domainValueGet = await this.getDomain(domain);
102
+ domainValueGet[key] = valueToUpdate;
103
+ await this.#updateDomain(domain, domainValueGet);
104
+ return await this.getDomain(domain);
105
+ }
108
106
 
109
107
  /**
110
- * @param domain 'xxx.xxxxx.xxx'
108
+ * @param {string} domain 'xxx.xxxxx.xxx'
111
109
  * @return {Promise<{}>}
112
110
  */
113
- clearThisDomain: async function (domain) {
114
- let domainValue = await this.getDomain(domain);
115
- await removeDomain(domain);
116
- return domainValue;
117
- },
118
- };
111
+ async clearThisDomain(domain) {
112
+ let domainValue = await this.getDomain(domain);
113
+ await this.#removeDomain(domain);
114
+ return domainValue;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * eg:
120
+ *
121
+ * "domain www.abcdefg.com":{
122
+ * "keyAAA": "valueBBB"
123
+ * }
124
+ *
125
+ * @returns {{getALLDomainKey: function(): Promise<string[]>, getALLDomainMap: function(): Promise<{domainList: *, domainKeyValueMap: {}}>, getDomain: function(string): Promise<{}>, updateDomainValueByOneKeyValue: function(string, string, string): Promise<{}>, clearThisDomain: function(*): Promise<{}>}}
126
+ */
127
+ export function baseORM() {
128
+
129
+ let keyPrefix = `domain `;
130
+ const domainKey = (k) => `${keyPrefix}${k}`;
131
+ const domainDefaultValue = {};
132
+
133
+ /**
134
+ * check domain exists, return true/false
135
+ * @param domain{string}
136
+ * @return {Promise<boolean>}
137
+ */
138
+ async function checkDomain(domain) {
139
+ return await stoOpCheck(domainKey(domain));
140
+ }
141
+
142
+ /**
143
+ * @param domain{string}
144
+ * @return {Promise<void>}
145
+ */
146
+ async function addDomain(domain) {
147
+ await stoOpSet(domainKey(domain), domainDefaultValue);
148
+ }
149
+
150
+ /**
151
+ * @param domain{string}
152
+ * @return {Promise<void>}
153
+ */
154
+ async function removeDomain(domain) {
155
+ await stoOpRem(domainKey(domain));
156
+ }
157
+
158
+ /**
159
+ * @param domain{string}
160
+ * @param valueNew
161
+ * @return {Promise<void>}
162
+ */
163
+ async function updateDomain(domain, valueNew) {
164
+ await stoOpSet(domainKey(domain), valueNew);
165
+ }
166
+
167
+ return {
168
+ /**
169
+ * eg: ['a.com', 'b.com', 'c.com']
170
+ * @returns {Promise<string[]>}
171
+ */
172
+ getALLDomainKey: async function () {
173
+ // stoOpQueryByPrefix
174
+ let strings = await stoOpQuery_startsWith(keyPrefix);
175
+ return strings.map(v => v.replaceAll(keyPrefix, ''));
176
+ },
177
+ getALLDomainMap: async function () {
178
+ let domainList = await this.getALLDomainKey();
179
+
180
+ // todo use for-loop not the reduce()!
181
+ const domainKeyValueMap = {}
182
+ for (let domain of domainList) {
183
+ domainKeyValueMap[domain] = await this.getDomain(domain)
184
+ }
185
+
186
+ return {domainList, domainKeyValueMap};
187
+ },
188
+
189
+ /**
190
+ *
191
+ * @param {string}domain
192
+ * @returns {Promise<{}>}
193
+ */
194
+ getDomain: async function (domain) {
195
+ if (!await checkDomain(domain)) {
196
+ await addDomain(domain);
197
+ }
198
+ return await stoOpGet(domainKey(domain));
199
+ },
200
+
201
+ /**
202
+ * {a:a1} => {a:a222}
203
+ * @param {string}domain 'xxx.xxxxx.xxx'
204
+ * @param{string}key
205
+ * @param {string}valueToUpdate
206
+ * @return {Promise<{}>}
207
+ */
208
+ updateDomainValueByOneKeyValue: async function (domain, key, valueToUpdate) {
209
+ if (!await checkDomain(domain)) {
210
+ await addDomain(domain);
211
+ }
212
+ let domainValueGet = await this.getDomain(domain);
213
+ domainValueGet[key] = valueToUpdate;
214
+ await updateDomain(domain, domainValueGet);
215
+ return (await this.getDomain(domain));
216
+ },
217
+
218
+ /**
219
+ * @param domain 'xxx.xxxxx.xxx'
220
+ * @return {Promise<{}>}
221
+ */
222
+ clearThisDomain: async function (domain) {
223
+ let domainValue = await this.getDomain(domain);
224
+ await removeDomain(domain);
225
+ return domainValue;
226
+ },
227
+ };
119
228
  }
package/src/baseOp.js CHANGED
@@ -1,140 +1,3 @@
1
- export async function stoOpCheck(k) {
2
- try {
3
- let key = k.toString();
4
-
5
- let objGet = await browser.storage.local.get(key);
6
- let b = objGet.hasOwnProperty(key);
7
- return b;
8
- } catch (e) {
9
- return false;
10
- }
11
- }
12
-
13
- export async function stoOpGet(k) {
14
- try {
15
- let key = k.toString();
16
- let objGet = await browser.storage.local.get(key);
17
- let v = objGet[key];
18
- return v;
19
- } catch (e) {
20
- return null;
21
- }
22
- }
23
-
24
- export async function stoOpGetAll() {
25
- try {
26
- return await browser.storage.local.get();
27
- } catch (e) {
28
- return null;
29
- }
30
- }
31
-
32
- export async function stoOpQuery_startsWith(k) {
33
- try {
34
- let objAll = await browser.storage.local.get();
35
- let keys = Object.keys(objAll);
36
- return keys.filter(value => value.startsWith(k.toString()));
37
- } catch (e) {
38
- return null;
39
- }
40
- }
41
-
42
- export async function stoOpSet(k, v) {
43
- let key = k.toString();
44
-
45
- let objNew = {};
46
- objNew[key] = v;
47
- await browser.storage.local.set(objNew);
48
- }
49
-
50
- export async function stoOpRem(k) {
51
- try {
52
- let key = k.toString();
53
- await browser.storage.local.remove(key);
54
- } catch (e) {
55
- }
56
- }
57
-
58
- export async function stoOpSetNull(k) {
59
- await stoOpSet(k, null);
60
- }
61
-
62
- /**
63
- *
64
- * @param tabId
65
- * @return {Promise<browser.tabs.Tab>}
66
- */
67
- export async function tabOpGet(tabId) {
68
- return await browser.tabs.get(tabId);
69
- }
70
-
71
- export async function tabOpQueryAll() {
72
- return await browser.tabs.query({});
73
- }
74
-
75
- export async function tabOpQueryUrl(urlQuery) {
76
- let tabs = await browser.tabs.query({url: urlQuery});
77
- return tabs.map(v => v.id);
78
- }
79
-
80
- export async function tabOpQueryUrlThenRem(urlQuery) {
81
- let ids = await tabOpQueryUrl(urlQuery);
82
- ids.map(id => tabOpRem(id));
83
- }
84
-
85
- export async function tabOpReload(tabId) {
86
- await browser.tabs.reload(tabId);
87
- }
88
-
89
- export async function tabOpCreate(args) {
90
- try {
91
- /**
92
- * @type {browser.tabs._CreateCreateProperties}
93
- */
94
- let source = {active: false, muted: true};
95
- Object.assign(args, source);
96
- return await browser.tabs.create(args);
97
- } catch (e) {
98
- }
99
- }
100
-
101
- export async function tabOpCreateNormal(args) {
102
- return await browser.tabs.create(args);
103
- }
104
-
105
- export async function tabOpRem(tabId) {
106
- try {
107
- await browser.tabs.remove(tabId);
108
- } catch (e) {
109
- }
110
- }
111
-
112
- export async function tabOpHide(tabId) {
113
- try {
114
- await browser.tabs.hide(tabId);
115
- } catch (e) {
116
- }
117
- }
118
-
119
- export async function tabOpUpdate(tabId, updateProperties) {
120
- await browser.tabs.update(tabId, updateProperties);
121
- }
122
-
123
- export async function tabOpUpdateActiveFalse(tabId) {
124
- await tabOpUpdate(tabId, {active: false, muted: true});
125
- }
126
-
127
- /**
128
- * @param tabId
129
- */
130
- export async function tabOpFocus(tabId) {
131
- let tab = await tabOpGet(tabId);
132
- let windowId = tab.windowId;
133
- await browser.windows.update(windowId, {focused: true});
134
-
135
- await tabOpUpdate(tabId,
136
- {active: true, highlighted: true});
137
- }
138
1
 
139
2
  export function objectOpFindTrueStorageTypeRadio(obj) {
140
3
  return Object.keys(obj).find((k) => {
@@ -0,0 +1,60 @@
1
+ export async function stoOpCheck(k) {
2
+ try {
3
+ let key = k.toString();
4
+
5
+ let objGet = await browser.storage.local.get(key);
6
+ let b = objGet.hasOwnProperty(key);
7
+ return b;
8
+ } catch (e) {
9
+ return false;
10
+ }
11
+ }
12
+
13
+ export async function stoOpGet(k) {
14
+ try {
15
+ let key = k.toString();
16
+ let objGet = await browser.storage.local.get(key);
17
+ let v = objGet[key];
18
+ return v;
19
+ } catch (e) {
20
+ return null;
21
+ }
22
+ }
23
+
24
+ export async function stoOpGetAll() {
25
+ try {
26
+ return await browser.storage.local.get();
27
+ } catch (e) {
28
+ return null;
29
+ }
30
+ }
31
+
32
+ export async function stoOpQuery_startsWith(k) {
33
+ try {
34
+ let objAll = await browser.storage.local.get();
35
+ let keys = Object.keys(objAll);
36
+ return keys.filter(value => value.startsWith(k.toString()));
37
+ } catch (e) {
38
+ return null;
39
+ }
40
+ }
41
+
42
+ export async function stoOpSet(k, v) {
43
+ let key = k.toString();
44
+
45
+ let objNew = {};
46
+ objNew[key] = v;
47
+ await browser.storage.local.set(objNew);
48
+ }
49
+
50
+ export async function stoOpRem(k) {
51
+ try {
52
+ let key = k.toString();
53
+ await browser.storage.local.remove(key);
54
+ } catch (e) {
55
+ }
56
+ }
57
+
58
+ export async function stoOpSetNull(k) {
59
+ await stoOpSet(k, null);
60
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ *
3
+ * @param tabId
4
+ * @return {Promise<browser.tabs.Tab>}
5
+ */
6
+ export async function tabOpGet(tabId) {
7
+ return await browser.tabs.get(tabId);
8
+ }
9
+
10
+ export async function tabOpQueryAll() {
11
+ return await browser.tabs.query({});
12
+ }
13
+
14
+ export async function tabOpQueryUrl(urlQuery) {
15
+ let tabs = await browser.tabs.query({url: urlQuery});
16
+ return tabs.map(v => v.id);
17
+ }
18
+
19
+ export async function tabOpQueryUrlThenRemove(urlQuery) {
20
+ let ids = await tabOpQueryUrl(urlQuery);
21
+ ids.map(id => tabOpRemove(id));
22
+ }
23
+
24
+ export async function tabOpReload(tabId) {
25
+ await browser.tabs.reload(tabId);
26
+ }
27
+
28
+ export async function tabOpCreate(args) {
29
+ try {
30
+ /**
31
+ * @type {browser.tabs._CreateCreateProperties}
32
+ */
33
+ let source = {active: false, muted: true};
34
+ Object.assign(args, source);
35
+ return await browser.tabs.create(args);
36
+ } catch (e) {
37
+ }
38
+ }
39
+
40
+ export async function tabOpCreateNormal(args) {
41
+ return await browser.tabs.create(args);
42
+ }
43
+
44
+ export async function tabOpRemove(tabId) {
45
+ try {
46
+ await browser.tabs.remove(tabId);
47
+ } catch (e) {
48
+ }
49
+ }
50
+
51
+ export async function tabOpHide(tabId) {
52
+ try {
53
+ await browser.tabs.hide(tabId);
54
+ } catch (e) {
55
+ }
56
+ }
57
+
58
+ /**
59
+ *
60
+ * @param {number}tabId
61
+ * @param {browser.tabs._UpdateUpdateProperties}updateProperties
62
+ * @returns {Promise<void>}
63
+ */
64
+ export async function tabOpUpdate(tabId, updateProperties) {
65
+ await browser.tabs.update(tabId, updateProperties);
66
+ }
67
+
68
+ export async function tabOpUpdateActiveFalse(tabId) {
69
+ await tabOpUpdate(tabId, {active: false, muted: true});
70
+ }
71
+
72
+ /**
73
+ * @param tabId
74
+ */
75
+ export async function tabOpFocus(tabId) {
76
+ let tab = await tabOpGet(tabId);
77
+ let windowId = tab.windowId;
78
+ await browser.windows.update(windowId, {focused: true});
79
+
80
+ await tabOpUpdate(tabId,
81
+ {active: true, highlighted: true});
82
+ }
83
+
84
+ /**
85
+ *
86
+ * @param{number} tabId
87
+ * @param {string}code
88
+ * @param {function}thenDoWhat
89
+ * @returns {Promise<void>}
90
+ */
91
+ export async function tabOpInsertCssCode(
92
+ tabId, code, thenDoWhat
93
+ ) {
94
+ await browser.tabs.insertCSS(tabId, {code})
95
+ thenDoWhat()
96
+ }