@vacantthinker/firefox-addon-framework-easy 2026.5.2203 → 2026.5.2205
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 +2 -0
- package/package.json +1 -1
- package/src/baseORM.js +119 -0
- package/src/baseRuntimeSetup.js +14 -5
package/index.js
CHANGED
package/package.json
CHANGED
package/src/baseORM.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stoOpCheck,
|
|
3
|
+
stoOpGet,
|
|
4
|
+
stoOpQuery_startsWith,
|
|
5
|
+
stoOpRem,
|
|
6
|
+
stoOpSet
|
|
7
|
+
} from "./baseOp.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* eg:
|
|
11
|
+
*
|
|
12
|
+
* "domain www.abcdefg.com":{
|
|
13
|
+
* "keyAAA": "valueBBB"
|
|
14
|
+
* }
|
|
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
|
+
*/
|
|
18
|
+
export function baseORM() {
|
|
19
|
+
|
|
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
|
+
/**
|
|
60
|
+
* eg: ['a.com', 'b.com', 'c.com']
|
|
61
|
+
* @returns {Promise<string[]>}
|
|
62
|
+
*/
|
|
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
|
+
},
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param {string}domain
|
|
83
|
+
* @returns {Promise<{}>}
|
|
84
|
+
*/
|
|
85
|
+
getDomain: async function (domain) {
|
|
86
|
+
if (!await checkDomain(domain)) {
|
|
87
|
+
await addDomain(domain);
|
|
88
|
+
}
|
|
89
|
+
return await stoOpGet(domainKey(domain));
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* {a:a1} => {a:a222}
|
|
94
|
+
* @param {string}domain 'xxx.xxxxx.xxx'
|
|
95
|
+
* @param{string}key
|
|
96
|
+
* @param {string}valueToUpdate
|
|
97
|
+
* @return {Promise<{}>}
|
|
98
|
+
*/
|
|
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
|
+
},
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param domain 'xxx.xxxxx.xxx'
|
|
111
|
+
* @return {Promise<{}>}
|
|
112
|
+
*/
|
|
113
|
+
clearThisDomain: async function (domain) {
|
|
114
|
+
let domainValue = await this.getDomain(domain);
|
|
115
|
+
await removeDomain(domain);
|
|
116
|
+
return domainValue;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
package/src/baseRuntimeSetup.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
+
import {serviceNotificationCreate} from "./baseService.js";
|
|
2
|
+
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
*
|
|
6
|
+
* @param{string} url
|
|
3
7
|
*/
|
|
4
|
-
export function baseRuntimeSetup(
|
|
8
|
+
export function baseRuntimeSetup(
|
|
9
|
+
url = 'https://addons.mozilla.org/en-US/firefox/user/17783213/'
|
|
10
|
+
) {
|
|
5
11
|
browser.runtime.onUpdateAvailable.addListener(details => {
|
|
6
|
-
|
|
12
|
+
serviceNotificationCreate(
|
|
13
|
+
"There is a new version!"
|
|
14
|
+
)
|
|
7
15
|
});
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
if (url) {
|
|
18
|
+
browser.runtime.setUninstallURL(url).then(r => {
|
|
19
|
+
});
|
|
20
|
+
}
|
|
12
21
|
}
|