@vacantthinker/firefox-addon-framework-easy 2026.5.2212 → 2026.524.1751

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.
@@ -0,0 +1,134 @@
1
+ /**
2
+ * color => node.style.color = color;
3
+ * @param message{{
4
+ * tabId:number,
5
+ * color:string
6
+ * }}
7
+ * @returns {Promise<void>}
8
+ */
9
+ export async function serviceUpdataALLTextNodeColor(message) {
10
+ let {tabId} = message;
11
+ const ass = Object.assign({}, message);
12
+ await browser.scripting.executeScript({
13
+ target: {tabId},
14
+ args: [ass],
15
+ /**
16
+ *
17
+ * @param message{{
18
+ * tabId: number,
19
+ * color:string,
20
+ * }}
21
+ * @returns {Promise<void>}
22
+ */
23
+ func: async (message) => {
24
+ // console.log('serviceShowPanelChangeTextStyle func(message)');
25
+ let {color} = message;
26
+ updateStyleColor(color);
27
+
28
+ function updateStyleColor(color) {
29
+ /**
30
+ *
31
+ * @returns {Node[]}
32
+ */
33
+ function nativeTreeWalkerFindALLElementHasNodeText() {
34
+ const walker = document.createTreeWalker(
35
+ document.body,
36
+ NodeFilter.SHOW_TEXT,
37
+ null,
38
+ );
39
+
40
+ let node;
41
+ /**
42
+ * @type {Node[]}
43
+ */
44
+ const textNodes = [];
45
+ while (node = walker.nextNode()) {
46
+ if (node.nodeName === '#text') {
47
+ textNodes.push(node.parentElement);
48
+ }
49
+ }
50
+ return Array.from(textNodes);
51
+ }
52
+
53
+ const arr = nativeTreeWalkerFindALLElementHasNodeText();
54
+ // console.info(arr);
55
+
56
+ if (arr.length) {
57
+ arr.forEach(value => {
58
+ value.style.color = color;
59
+ });
60
+ }
61
+ }
62
+
63
+ // todo end
64
+ },
65
+ });
66
+ }
67
+
68
+ /**
69
+ * node.style.backgroundColor = color;
70
+ * @param message{{
71
+ * tabId:number,
72
+ * backgroundColor:string
73
+ * }}
74
+ * @returns {Promise<void>}
75
+ */
76
+ export async function serviceUpdataALLNodeBackgroundColor(message) {
77
+ let {tabId} = message;
78
+ const ass = Object.assign({}, message);
79
+ await browser.scripting.executeScript({
80
+ target: {tabId},
81
+ args: [ass],
82
+ /**
83
+ *
84
+ * @param message{{
85
+ * tabId: number,
86
+ * backgroundColor:string,
87
+ * }}
88
+ * @returns {Promise<void>}
89
+ */
90
+ func: async (message) => {
91
+ // console.log('serviceShowPanelChangeTextStyle func(message)');
92
+ let {backgroundColor} = message;
93
+ updateStyleBackgroundColor(backgroundColor);
94
+
95
+ function updateStyleBackgroundColor(backgroundColor) {
96
+ /**
97
+ *
98
+ * @returns {Node[]}
99
+ */
100
+ function nativeTreeWalker() {
101
+ const walker = document.createTreeWalker(
102
+ document.body,
103
+ NodeFilter.SHOW_ELEMENT,
104
+ null,
105
+ );
106
+
107
+ let node;
108
+ /**
109
+ * @type {Node[]}
110
+ */
111
+ const textNodes = [];
112
+ while (node = walker.nextNode()) {
113
+ textNodes.push(node);
114
+ }
115
+ return Array.from(textNodes);
116
+ }
117
+
118
+ /**
119
+ * @type {Node[]}
120
+ */
121
+ const arr = nativeTreeWalker();
122
+ // console.info(arr);
123
+
124
+ if (arr.length) {
125
+ arr.forEach(value => {
126
+ value.style.backgroundColor = backgroundColor;
127
+ });
128
+ }
129
+ }
130
+
131
+ // todo end
132
+ },
133
+ });
134
+ }
@@ -0,0 +1,54 @@
1
+ import {stoOpGet, stoOpSet} from './opStorage.js';
2
+
3
+ /**
4
+ *
5
+ * searchEngine: {
6
+ * optionType: 'checkbox',
7
+ * options: ['Searcher1', 'Searcher2'],
8
+ * selected: ['Searcher1', 'Searcher2'],
9
+ * queryTitle: {
10
+ * 'Searcher1': 'https://y2down.cc/',
11
+ * 'Searcher2': 'https://ssyou.online',
12
+ * },
13
+ * },
14
+ * videoQuality: {
15
+ * options: ['360', '480', '720', '1080', '1440', '2160'],
16
+ * selected: '720',
17
+ * },
18
+ *
19
+ * @param userSettings{{}}
20
+ * @returns {Promise<void>}
21
+ */
22
+ export async function serviceInitUserSettings(userSettings) {
23
+ for (const k of Object.keys(userSettings)) {
24
+ let v = userSettings[k];
25
+ let options = v.options;
26
+ let selected = v.selected;
27
+
28
+ // todo check if has oldvalue donothing, else set k and v
29
+ let oldValue = await stoOpGet(k);
30
+ if (oldValue) {
31
+ }
32
+ else {
33
+ await stoOpSet(k, selected);
34
+ }
35
+
36
+ }
37
+ }
38
+
39
+ /**
40
+ * // todo 当前这个文件 建议使用生成式脚本来处理
41
+ * @param userSettings{{}}
42
+ * @returns {Promise<{}>}
43
+ */
44
+ export async function serviceGetUserSettings(userSettings) {
45
+ const red = {};
46
+ for (let k of Object.keys(userSettings)) {
47
+ red[k] = await stoOpGet(k);
48
+ }
49
+ return red;
50
+ }
51
+
52
+
53
+
54
+
package/src/baseOp.js DELETED
@@ -1,9 +0,0 @@
1
-
2
- export function objectOpFindTrueStorageTypeRadio(obj) {
3
- return Object.keys(obj).find((k) => {
4
- let v = obj[k];
5
- if (v) {
6
- return k;
7
- }
8
- });
9
- }
@@ -1,60 +0,0 @@
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
- }
package/src/baseOpTab.js DELETED
@@ -1,102 +0,0 @@
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
- * @returns {Promise<void>}
89
- */
90
- export async function tabOpInsertCssCode(tabId, code) {
91
- await browser.tabs.insertCSS(tabId, {code})
92
- }
93
-
94
- /**
95
- *
96
- * @param{number} tabId
97
- * @param {string}code
98
- * @returns {Promise<void>}
99
- */
100
- export async function tabOpRemoveCssCode(tabId, code) {
101
- await browser.tabs.removeCSS(tabId, {code})
102
- }
@@ -1,21 +0,0 @@
1
- import {serviceNotificationCreate} from "./baseService.js";
2
-
3
-
4
- /**
5
- *
6
- * @param{string} url
7
- */
8
- export function baseRuntimeSetup(
9
- url = 'https://addons.mozilla.org/en-US/firefox/user/17783213/'
10
- ) {
11
- browser.runtime.onUpdateAvailable.addListener(details => {
12
- serviceNotificationCreate(
13
- "There is a new version!"
14
- )
15
- });
16
-
17
- if (url) {
18
- browser.runtime.setUninstallURL(url).then(r => {
19
- });
20
- }
21
- }
@@ -1,110 +0,0 @@
1
-
2
- /**
3
- *
4
- * @param { string}content
5
- * @param {string|null}title
6
- * @returns {Promise<void>}
7
- */
8
- export async function serviceNotificationCreate(content, title = null) {
9
- const tag = "base_notifi"
10
- try {
11
- let notificationId = "cake-noti";
12
- title = title ? title : browser.runtime.getManifest().name;
13
- console.info(tag, `content=${content}`, `title=${title}`)
14
- await browser.notifications.create(notificationId, {
15
- type: "basic",
16
- title,
17
- message: content,
18
- });
19
- } catch (e) {
20
- console.error(tag, e)
21
- }
22
-
23
- }
24
-
25
- /**
26
- *
27
- * @param{string} content
28
- */
29
- export function serviceCopyContentToClipboard(content) {
30
- window.navigator.clipboard.writeText(content).then(r => null);
31
- }
32
-
33
- export function serviceGetRuntimeManifestVersion() {
34
- return browser.runtime.getManifest().version;
35
- }
36
- export async function serviceGetRuntimePlatformInfo() {
37
- return await browser.runtime.getPlatformInfo();
38
- }
39
-
40
- /**
41
- *
42
- * @type {{txt: string, json: string, cmd: string, js: string}}
43
- */
44
- export const fileExt = {
45
- txt: "txt",
46
- json: "json",
47
- cmd: "cmd",
48
- js: "js",
49
- }
50
-
51
- /**
52
- * eg: fnName('this is content', 'this is a filename without ext', 'txt')
53
- * @param {string} content
54
- * @param {string} filename eg: abc
55
- * @param {string} ext txt json cmd js ...
56
- */
57
- export function serviceSaveContentToLocal(content, filename, ext = "txt") {
58
- const eleBtn = document.createElement("button");
59
- eleBtn.addEventListener(
60
- "click",
61
- function () {
62
- const eleA = document.createElement("a");
63
- let type = "text/plain";
64
- // let type = 'application/json';
65
-
66
- const file = new Blob([content], {type});
67
- eleA.href = URL.createObjectURL(file);
68
- eleA.download = [filename, ext].join(".");
69
- eleA.click();
70
- URL.revokeObjectURL(eleA.href);
71
- },
72
- false,
73
- );
74
- eleBtn.click();
75
- // eleBtn.previousElementSibling
76
- }
77
-
78
-
79
- /**
80
- *
81
- * @param {string} value
82
- * @returns {string}
83
- */
84
- export function serviceRemoveIllegalWord(value) {
85
- let searchValue = /[\/\\\[\]\-"『』<>›::;❗”“'|丨|⦇⦈??!!「」【】─\(\)()《》*#$@&%、,,。+·•]/g;
86
- let name0 = value.trim().split(/\r?\n/).shift();
87
- let name1 = name0.replace(searchValue, ' ');
88
- let name2 = name1.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ' ');
89
- return name2;
90
- }
91
-
92
- /**
93
- * serviceGetDateNow() 11h_47m_24s_302
94
- * @return {string}
95
- */
96
- export function serviceGetCurrentDateYYYYMMDDHHMMSS() {
97
- let date = new Date();
98
- let m = [
99
- [date.getFullYear(), ""].join(""),
100
- [date.getMonth() + 1, ""].join(""),
101
- [date.getDate(), ""].join(""),
102
-
103
- [date.getHours(), "h"].join(""),
104
- [date.getMinutes(), "m"].join(""),
105
- [date.getSeconds(), "s"].join(""),
106
- date.getMilliseconds(),
107
- ];
108
- let r = m.join("_");
109
- return r;
110
- }
@@ -1,24 +0,0 @@
1
- /**
2
- *
3
- * @param {string}videolinkOrigin
4
- * @returns {{
5
- * videolink: string,
6
- * vid: string
7
- *
8
- * }|null}
9
- */
10
- export function servicePureVideolinkYTB(videolinkOrigin) {
11
- if (!videolinkOrigin) {
12
- return null;
13
- }
14
-
15
- const u = new URL(videolinkOrigin)
16
- let vid = u.searchParams.get('v');
17
-
18
- let searchValue = '/shorts/';
19
- if (u.pathname.startsWith(searchValue)) {
20
- vid = u.pathname.replace(searchValue, '')
21
- }
22
- let videolink = `https://www.youtube.com/watch?v=${vid}`
23
- return {videolink, vid}
24
- }
@@ -1,99 +0,0 @@
1
- /**
2
- *
3
- * // zip dist dir => output: current-project-name.zip
4
- * zipFilesOrDirectorys(null, 'dist');
5
- *
6
- *
7
- *
8
- * // zip all files all dirs , ignore [.git, .idea, node_modules, dist]
9
- * => output: curret-project-name-ALL.zip
10
- * zipFilesOrDirectorys(
11
- * 'ALL',
12
- * null,
13
- * {
14
- * "exclude": ['.git', '.idea', 'node_modules', 'dist'],
15
- * "suffix": ['.zip']
16
- * }
17
- * );
18
- *
19
- * @param outputAppendName{string|null}
20
- * @param oneDirecoty{string|null}
21
- * @param ignoreObj{{
22
- * exclude: [string],
23
- * suffix: [string]
24
- * }|null}
25
- */
26
- export function zipFilesOrDirectorys(
27
- outputAppendName,
28
- oneDirecoty = null,
29
- ignoreObj = null) {
30
-
31
- const archiver = require('archiver')
32
- const fs = require('fs')
33
- const path = require('path')
34
- const basename = path.basename(__dirname)
35
-
36
- const arrFilename = Array.from([basename])
37
- if (outputAppendName) {
38
- arrFilename.push(outputAppendName)
39
- }
40
- const output = fs.createWriteStream(
41
- path.join(__dirname, `${arrFilename.join('-')}.zip`))
42
- const archive = archiver('zip')
43
- output.on('close', () => {
44
- console.info(`${outputAppendName} zip finish!`)
45
- })
46
- archive.on('error', (e) => {
47
- console.info('e=');
48
- console.info(e);
49
- })
50
-
51
- archive.pipe(output)
52
-
53
- if (oneDirecoty) {
54
- // todo one dir
55
- archive.directory(`${oneDirecoty}/`, false)
56
- } else if (ignoreObj) {
57
- let strings = fs.readdirSync(__dirname);
58
-
59
- let {exclude, suffix} = ignoreObj
60
- let arrFilter = strings
61
- .filter(name => !exclude.includes(name))
62
- .filter(name => !suffix.some(value => name.endsWith(value)))
63
- console.info('arrFilter=');
64
- console.info(arrFilter);
65
-
66
- arrFilter.forEach(filename => {
67
- let pathFile = path.join(__dirname, filename);
68
- let stats = fs.lstatSync(pathFile);
69
- if (stats.isDirectory()) {
70
- archive.directory(`${filename}/`)
71
- } else if (stats.isFile()) {
72
- archive.file(pathFile, {name: filename})
73
- }
74
- })
75
- } else {
76
-
77
- }
78
-
79
- archive.finalize();
80
- console.info(`${outputAppendName} zip starting`)
81
- }
82
-
83
- export function zipFilesOrDirectorysDist() {
84
- zipFilesOrDirectorys(null, 'dist');
85
- }
86
-
87
- export function zipFilesOrDirectorysALL() {
88
- zipFilesOrDirectorys(
89
- 'ALL',
90
- null,
91
- {
92
- "exclude": ['.git', '.idea', 'node_modules', 'dist'],
93
- "suffix": ['.zip']
94
- }
95
- );
96
- }
97
-
98
-
99
-
package/webpack.config.js DELETED
@@ -1,96 +0,0 @@
1
-
2
- //=============================================================================
3
- const path = require("path");
4
-
5
- const fs = require("fs");
6
- const CopyPlugin = require("copy-webpack-plugin");
7
- let pathDirSrc = path.join(__dirname, "addons");
8
-
9
- let pathDirDest = path.join(__dirname, "dist");
10
-
11
- let arrJsFile = [
12
- { type: "file", name: "background" },
13
- ];
14
-
15
- // todo entry javascript file
16
- let entry = geneEntry(arrJsFile, pathDirSrc);
17
-
18
- // todo which file do you want to copy ?
19
- const patterns = geneCopyPatterns(
20
- [
21
- "_locales", //
22
- // "icons", // icon
23
- "background.html", //
24
- "LICENSE", //
25
- "manifest.json", //
26
- ],
27
- pathDirSrc,
28
- pathDirDest
29
- );
30
-
31
-
32
- //************************************************************************
33
- //************************************************************************
34
- //************************************************************************
35
- //************************************************************************
36
-
37
- // entry only support js file
38
- module.exports = {
39
- mode: "production", // production
40
- entry: entry,
41
- output: {
42
- path: pathDirDest,
43
- filename: "[name]",
44
- },
45
- experiments: {
46
- topLevelAwait: true,
47
- },
48
- plugins: [new CopyPlugin({ patterns: patterns })],
49
- };
50
-
51
- function geneEntry(arr, pathBase) {
52
- const path = require("path");
53
- const fs = require("fs");
54
- let reduce = arr.reduce((result, item) => {
55
- let { type, name } = item;
56
-
57
- if (String(type).includes("file")) {
58
- let filename = `${name}.js`;
59
- result[filename] = path.join(pathBase, filename);
60
- }
61
- if (String(type).includes("dir")) {
62
- let strings = fs.readdirSync(path.join(pathBase, name));
63
- strings
64
- .filter((value) => value.endsWith(".js"))
65
- .forEach((filename) => {
66
- let key_ = `${name}/${filename}`;
67
- result[key_] = path.join(pathBase, name, filename);
68
- });
69
- }
70
-
71
- return result;
72
- }, {});
73
-
74
- console.log(`meslog reduce=\n`, reduce);
75
-
76
- return reduce;
77
- }
78
-
79
- /**
80
- *
81
- * @param arr{Array} src file/dir arr
82
- * @param src{String} src path
83
- * @param dest{String} dest path
84
- * @return Array
85
- */
86
- function geneCopyPatterns(arr, src, dest) {
87
- const path = require("path");
88
- const fs = require("fs");
89
- return arr.reduce((result, value) => {
90
- let a = path.join(src, value);
91
- let b = path.join(dest, value);
92
- let obj = { from: a, to: b };
93
- result.push(obj);
94
- return result;
95
- }, Array.from([]));
96
- }