@vacantthinker/firefox-addon-framework-easy 2026.611.821 → 2026.611.1153
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/README.md +0 -217
- package/dist/BaseORM.d.ts +41 -0
- package/dist/BaseORM.d.ts.map +1 -0
- package/dist/BaseORM.js +77 -0
- package/dist/browserDownload.d.ts +9 -0
- package/dist/browserDownload.d.ts.map +1 -0
- package/dist/browserDownload.js +10 -0
- package/dist/browserNotification.d.ts +8 -0
- package/dist/browserNotification.d.ts.map +1 -0
- package/dist/browserNotification.js +17 -0
- package/dist/browserRuntime.d.ts +41 -0
- package/dist/browserRuntime.d.ts.map +1 -0
- package/dist/browserRuntime.js +61 -0
- package/dist/browserTab.d.ts +34 -0
- package/dist/browserTab.d.ts.map +1 -0
- package/dist/browserTab.js +105 -0
- package/dist/generate.d.ts +13 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +99 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/opStorage.d.ts +40 -0
- package/dist/opStorage.d.ts.map +1 -0
- package/dist/opStorage.js +57 -0
- package/dist/opTab.d.ts +82 -0
- package/dist/opTab.d.ts.map +1 -0
- package/dist/opTab.js +152 -0
- package/dist/serviceCommon.d.ts +8 -0
- package/dist/serviceCommon.d.ts.map +1 -0
- package/dist/serviceCommon.js +21 -0
- package/dist/serviceFetch.d.ts +23 -0
- package/dist/serviceFetch.d.ts.map +1 -0
- package/dist/serviceFetch.js +38 -0
- package/dist/serviceGet.d.ts +13 -0
- package/dist/serviceGet.d.ts.map +1 -0
- package/dist/serviceGet.js +24 -0
- package/dist/serviceOpContent.d.ts +24 -0
- package/dist/serviceOpContent.d.ts.map +1 -0
- package/dist/serviceOpContent.js +69 -0
- package/dist/serviceOpJavascript.d.ts +41 -0
- package/dist/serviceOpJavascript.d.ts.map +1 -0
- package/dist/serviceOpJavascript.js +182 -0
- package/dist/servicePure.d.ts +18 -0
- package/dist/servicePure.d.ts.map +1 -0
- package/dist/servicePure.js +51 -0
- package/dist/serviceUpdateTabStyle.d.ts +17 -0
- package/dist/serviceUpdateTabStyle.d.ts.map +1 -0
- package/dist/serviceUpdateTabStyle.js +63 -0
- package/package.json +11 -4
- package/.github/workflows/npm-publish.yml +0 -34
- package/index.js +0 -17
- package/publish.sh +0 -81
- package/src/BaseORM.js +0 -66
- package/src/DomainORM.js +0 -11
- package/src/browserDownload.js +0 -23
- package/src/browserNotification.js +0 -22
- package/src/browserRuntime.js +0 -65
- package/src/browserRuntimeOnMessageCommon.js +0 -50
- package/src/browserTab.js +0 -138
- package/src/generate.js +0 -177
- package/src/opStorage.js +0 -76
- package/src/opTab.js +0 -237
- package/src/serviceCommon.js +0 -22
- package/src/serviceFetch.js +0 -65
- package/src/serviceGet.js +0 -31
- package/src/serviceOpContent.js +0 -83
- package/src/serviceOpJavascript.js +0 -346
- package/src/servicePure.js +0 -42
- package/src/serviceUpdateTabStyle.js +0 -130
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
import {serviceGetCurrentDateYYYYMMDDHHMMSS} from './serviceGet.js';
|
|
2
|
-
import {
|
|
3
|
-
serviceCopyContentToClipboard,
|
|
4
|
-
serviceRemoveIllegalWord,
|
|
5
|
-
serviceSaveContentToLocal,
|
|
6
|
-
} from './serviceOpContent.js';
|
|
7
|
-
import {browserNotificationCreate} from './browserNotification.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param param0
|
|
12
|
-
* @param param0.tabId {number}
|
|
13
|
-
* @param param0.filename {string}
|
|
14
|
-
* @param param0.rect {{
|
|
15
|
-
* x,
|
|
16
|
-
* y,
|
|
17
|
-
* width,
|
|
18
|
-
* height,
|
|
19
|
-
* }}
|
|
20
|
-
* @returns {Promise<void>}
|
|
21
|
-
*/
|
|
22
|
-
export async function serviceTakeScreenshot(
|
|
23
|
-
{
|
|
24
|
-
tabId,
|
|
25
|
-
filename,
|
|
26
|
-
rect,
|
|
27
|
-
}) {
|
|
28
|
-
|
|
29
|
-
const tag = 'actTakeScreenshot()';
|
|
30
|
-
let dataURI = await browser.tabs.captureTab(tabId, {
|
|
31
|
-
rect: rect,
|
|
32
|
-
});
|
|
33
|
-
let assign = Object.assign(
|
|
34
|
-
{},
|
|
35
|
-
{dataURI, filename},
|
|
36
|
-
);
|
|
37
|
-
await browser.scripting.executeScript({
|
|
38
|
-
target: {tabId},
|
|
39
|
-
args: [assign],
|
|
40
|
-
func: function(message) {
|
|
41
|
-
if (message) {
|
|
42
|
-
let {dataURI, filename} = message;
|
|
43
|
-
|
|
44
|
-
imageDataToLocalFile({dataURI, filename});
|
|
45
|
-
|
|
46
|
-
function imageDataToLocalFile({dataURI, filename}) {
|
|
47
|
-
let a = document.createElement('a');
|
|
48
|
-
a.href = dataURI;
|
|
49
|
-
a.download = filename;
|
|
50
|
-
a.click();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// todo end if(message)
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* middle ware, output => {rect, uniqueSelector,}
|
|
62
|
-
* @param message{{
|
|
63
|
-
* tabId:number,
|
|
64
|
-
* act:string
|
|
65
|
-
* }}
|
|
66
|
-
* @returns {Promise<void>}
|
|
67
|
-
*/
|
|
68
|
-
export async function serviceElementPicker(message) {
|
|
69
|
-
let {tabId} = message;
|
|
70
|
-
await browser.scripting.executeScript({
|
|
71
|
-
target: {tabId},
|
|
72
|
-
args: [message],
|
|
73
|
-
func: async function(message) {
|
|
74
|
-
if (!message) return;
|
|
75
|
-
console.log('picker.js initialized', message);
|
|
76
|
-
|
|
77
|
-
// 1. Create a dedicated "Always On Top" highlighter overlay
|
|
78
|
-
const overlayId = 'extension-element-highlighter-overlay';
|
|
79
|
-
let overlay = document.getElementById(overlayId);
|
|
80
|
-
|
|
81
|
-
if (!overlay) {
|
|
82
|
-
overlay = document.createElement('div');
|
|
83
|
-
overlay.id = overlayId;
|
|
84
|
-
// !important and max z-index guarantees it will never be hidden by site CSS
|
|
85
|
-
overlay.style.cssText = `
|
|
86
|
-
position: fixed !important;
|
|
87
|
-
top: 0 !important;
|
|
88
|
-
left: 0 !important;
|
|
89
|
-
width: 0 !important;
|
|
90
|
-
height: 0 !important;
|
|
91
|
-
background-color: rgba(255, 0, 85, 0.2) !important;
|
|
92
|
-
outline: 2px dashed #ff0055 !important;
|
|
93
|
-
outline-offset: -2px !important;
|
|
94
|
-
z-index: 2147483647 !important;
|
|
95
|
-
pointer-events: none !important;
|
|
96
|
-
transition: all 0.05s ease-out !important;
|
|
97
|
-
display: none !important;
|
|
98
|
-
`;
|
|
99
|
-
// Appending to documentElement (<html>) avoids <body> layout restrictions
|
|
100
|
-
document.documentElement.appendChild(overlay);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getUniqueSelector(el) {
|
|
104
|
-
if (!(el instanceof Element)) return '';
|
|
105
|
-
const path = [];
|
|
106
|
-
while (el.nodeType === Node.ELEMENT_NODE) {
|
|
107
|
-
let selector = el.nodeName.toLowerCase();
|
|
108
|
-
if (el.id) {
|
|
109
|
-
selector += '#' + el.id;
|
|
110
|
-
path.unshift(selector);
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
let sib = el, nth = 1;
|
|
115
|
-
while (sib = sib.previousElementSibling) {
|
|
116
|
-
if (sib.nodeName.toLowerCase() === selector) nth++;
|
|
117
|
-
}
|
|
118
|
-
if (nth !== 1) selector += `:nth-of-type(${nth})`;
|
|
119
|
-
}
|
|
120
|
-
path.unshift(selector);
|
|
121
|
-
el = el.parentNode;
|
|
122
|
-
}
|
|
123
|
-
return path.join(' > ');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function handleMouseOver(e) {
|
|
127
|
-
const target = e.target;
|
|
128
|
-
|
|
129
|
-
// Safety check to ensure we don't try to highlight our own UI
|
|
130
|
-
if (target.id === overlayId) return;
|
|
131
|
-
|
|
132
|
-
// Get exact coordinates of the hovered element
|
|
133
|
-
const clientRect = target.getBoundingClientRect();
|
|
134
|
-
|
|
135
|
-
// Move the floating overlay exactly over the target
|
|
136
|
-
overlay.style.setProperty('display', 'block', 'important');
|
|
137
|
-
overlay.style.setProperty('top', `${clientRect.top}px`, 'important');
|
|
138
|
-
overlay.style.setProperty('left', `${clientRect.left}px`, 'important');
|
|
139
|
-
overlay.style.setProperty('width', `${clientRect.width}px`,
|
|
140
|
-
'important');
|
|
141
|
-
overlay.style.setProperty('height', `${clientRect.height}px`,
|
|
142
|
-
'important');
|
|
143
|
-
|
|
144
|
-
// Change mouse cursor to indicate picking mode
|
|
145
|
-
document.body.style.setProperty('cursor', 'crosshair', 'important');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async function handleElementClick(e) {
|
|
149
|
-
e.preventDefault();
|
|
150
|
-
e.stopPropagation();
|
|
151
|
-
|
|
152
|
-
const target = e.target;
|
|
153
|
-
|
|
154
|
-
// Clean up the picker completely
|
|
155
|
-
stopPickingMode();
|
|
156
|
-
|
|
157
|
-
// Calculate screenshot coordinates
|
|
158
|
-
let clientRect = target.getBoundingClientRect();
|
|
159
|
-
let rect = {
|
|
160
|
-
height: clientRect.height,
|
|
161
|
-
width: clientRect.width,
|
|
162
|
-
x: clientRect.left + window.scrollX,
|
|
163
|
-
y: clientRect.top + window.scrollY,
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
// Assuming 'target' is your clicked element (e.g., from e.target)
|
|
167
|
-
let messageTakeScreenshot = Object.assign(
|
|
168
|
-
{}, // Start with a fresh, empty object
|
|
169
|
-
message, // Put the original message first so it doesn't overwrite your new data
|
|
170
|
-
{rect},
|
|
171
|
-
{
|
|
172
|
-
// The guaranteed unique CSS path (e.g., "div#wrap > ul > li:nth-of-type(2)")
|
|
173
|
-
uniqueSelector: getUniqueSelector(target),
|
|
174
|
-
},
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
await browser.runtime.sendMessage(messageTakeScreenshot);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function startPickingMode() {
|
|
181
|
-
document.addEventListener('mouseover', handleMouseOver, true);
|
|
182
|
-
document.addEventListener('click', handleElementClick, true);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function stopPickingMode() {
|
|
186
|
-
document.removeEventListener('mouseover', handleMouseOver, true);
|
|
187
|
-
document.removeEventListener('click', handleElementClick, true);
|
|
188
|
-
|
|
189
|
-
// Restore normal mouse cursor
|
|
190
|
-
document.body.style.removeProperty('cursor');
|
|
191
|
-
|
|
192
|
-
// Remove the overlay from the DOM entirely
|
|
193
|
-
if (overlay) {
|
|
194
|
-
overlay.remove();
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Initialize the picker mode
|
|
199
|
-
startPickingMode();
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* middle ware, output: {rect}
|
|
206
|
-
*
|
|
207
|
-
* @param message{{
|
|
208
|
-
* tabId:number,
|
|
209
|
-
* act:string
|
|
210
|
-
* }}
|
|
211
|
-
* @returns {Promise<void>}
|
|
212
|
-
*/
|
|
213
|
-
export async function serviceGetFullPageRectData(message) {
|
|
214
|
-
let {tabId} = message;
|
|
215
|
-
|
|
216
|
-
await browser.scripting.executeScript({
|
|
217
|
-
target: {tabId},
|
|
218
|
-
args: [message],
|
|
219
|
-
func: (message) => {
|
|
220
|
-
|
|
221
|
-
let x = 0, y = 0;
|
|
222
|
-
let width = document.documentElement.scrollWidth;
|
|
223
|
-
let height = document.documentElement.scrollHeight;
|
|
224
|
-
let rect = {
|
|
225
|
-
x, y, width, height,
|
|
226
|
-
};
|
|
227
|
-
browser.runtime.sendMessage(Object.assign(
|
|
228
|
-
{},
|
|
229
|
-
message,
|
|
230
|
-
{rect},
|
|
231
|
-
));
|
|
232
|
-
// todo end if (message)
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* middle ware, output: Object.assign({}, message, {data})
|
|
239
|
-
*
|
|
240
|
-
* serviceFindAllMagnetLink({
|
|
241
|
-
* tabId, title, act, ...
|
|
242
|
-
* })
|
|
243
|
-
*
|
|
244
|
-
* @param message{{
|
|
245
|
-
* tabId:number,
|
|
246
|
-
* title:string,
|
|
247
|
-
* act: string,
|
|
248
|
-
* }}
|
|
249
|
-
*/
|
|
250
|
-
export async function serviceFindAllMagnetLink(message) {
|
|
251
|
-
let {tabId} = message;
|
|
252
|
-
const assign = Object.assign({}, message);
|
|
253
|
-
|
|
254
|
-
await browser.scripting.executeScript({
|
|
255
|
-
target: {tabId},
|
|
256
|
-
args: [assign],
|
|
257
|
-
func: async (message) => {
|
|
258
|
-
if (message) {
|
|
259
|
-
function findAllMagnetLinks() {
|
|
260
|
-
const magnets = new Set(); // Prevents duplicates
|
|
261
|
-
|
|
262
|
-
// --- Type 1: Find inside ANY element's attributes ---
|
|
263
|
-
const attributeSelector = '*[href*="magnet:"], *[data-url*="magnet:"], *[data-magnet*="magnet:"], *[data-href*="magnet:"]';
|
|
264
|
-
const attrElements = document.querySelectorAll(attributeSelector);
|
|
265
|
-
|
|
266
|
-
attrElements.forEach(el => {
|
|
267
|
-
// Check every attribute of the element to find the one holding the magnet string
|
|
268
|
-
for (let attr of el.attributes) {
|
|
269
|
-
if (attr.value.includes('magnet:?xt=')) {
|
|
270
|
-
magnets.add(attr.value.trim());
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
// --- Type 2: Find inside raw text (for <div>, <span>, <td>, etc.) ---
|
|
276
|
-
// We target elements that don't have children to avoid grabbing huge parent container blocks
|
|
277
|
-
const allElements = document.querySelectorAll(
|
|
278
|
-
'div, span, td, p, a, button');
|
|
279
|
-
allElements.forEach(el => {
|
|
280
|
-
if (el.children.length === 0) { // Deepest element
|
|
281
|
-
const text = el.textContent.trim();
|
|
282
|
-
if (text.includes('magnet:?xt=')) {
|
|
283
|
-
// Extract just the magnet link using Regex in case there is surrounding text
|
|
284
|
-
const match = text.match(/magnet:\?xt=[^\s"'<>]+/);
|
|
285
|
-
if (match) {
|
|
286
|
-
magnets.add(match[0]);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
return Array.from(magnets);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
await browser.runtime.sendMessage(Object.assign(
|
|
296
|
-
{},
|
|
297
|
-
message,
|
|
298
|
-
{
|
|
299
|
-
data: findAllMagnetLinks(),
|
|
300
|
-
},
|
|
301
|
-
));
|
|
302
|
-
|
|
303
|
-
// todo end if(message)
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
*
|
|
311
|
-
* @param message{{
|
|
312
|
-
* title:string,
|
|
313
|
-
* data: [string],
|
|
314
|
-
* handleOption: 'clipboard'|'txt'|'clipboardAndTxt'
|
|
315
|
-
* }}
|
|
316
|
-
* @returns {Promise<void>}
|
|
317
|
-
*/
|
|
318
|
-
export async function serviceDealWithMagnetLink(message) {
|
|
319
|
-
|
|
320
|
-
let {title, data, handleOption} = message;
|
|
321
|
-
let titleCleaned = serviceRemoveIllegalWord(title);
|
|
322
|
-
|
|
323
|
-
if (Array.isArray(data) && data.length >= 1) {
|
|
324
|
-
let content = `${data.join('\n')}\n`;
|
|
325
|
-
|
|
326
|
-
let filename = [
|
|
327
|
-
'magnet-link',
|
|
328
|
-
titleCleaned,
|
|
329
|
-
serviceGetCurrentDateYYYYMMDDHHMMSS()].join(' ');
|
|
330
|
-
|
|
331
|
-
if (handleOption === 'clipboard') {
|
|
332
|
-
await serviceCopyContentToClipboard(content);
|
|
333
|
-
}
|
|
334
|
-
else if (handleOption === 'txt') {
|
|
335
|
-
serviceSaveContentToLocal(content, filename);
|
|
336
|
-
}
|
|
337
|
-
else if (handleOption === 'clipboardAndTxt') {
|
|
338
|
-
await serviceCopyContentToClipboard(content);
|
|
339
|
-
serviceSaveContentToLocal(content, filename);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
// todo notification => magnet link not found!
|
|
344
|
-
await browserNotificationCreate('magnet link not found!');
|
|
345
|
-
}
|
|
346
|
-
}
|
package/src/servicePure.js
DELETED
|
@@ -1,42 +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
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* https://www.youtube.com/playlist?list=PLo6dUe-n7Er913xrQrvCEzHAU5_krsekL
|
|
28
|
-
*
|
|
29
|
-
* @param videolinkOrigin{string}
|
|
30
|
-
* @returns {{playlistVideolink: string, playlistId: string}|null}
|
|
31
|
-
*/
|
|
32
|
-
export function servicePurePlaylistVideolinkYTB(videolinkOrigin) {
|
|
33
|
-
if (!videolinkOrigin) return null;
|
|
34
|
-
|
|
35
|
-
const u = new URL(videolinkOrigin);
|
|
36
|
-
let playlistId = u.searchParams.get('list');
|
|
37
|
-
|
|
38
|
-
let prefix = 'https://www.youtube.com/playlist?list=';
|
|
39
|
-
let playlistVideolink = `${prefix}${playlistId}`;
|
|
40
|
-
const ret = {playlistVideolink, playlistId};
|
|
41
|
-
return ret;
|
|
42
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
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
|
-
let {color} = message;
|
|
25
|
-
updateStyleColor(color);
|
|
26
|
-
|
|
27
|
-
function updateStyleColor(color) {
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
* @returns {Node[]}
|
|
31
|
-
*/
|
|
32
|
-
function nativeTreeWalkerFindALLElementHasNodeText() {
|
|
33
|
-
const walker = document.createTreeWalker(
|
|
34
|
-
document.body,
|
|
35
|
-
NodeFilter.SHOW_TEXT,
|
|
36
|
-
null,
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
let node;
|
|
40
|
-
/**
|
|
41
|
-
* @type {Node[]}
|
|
42
|
-
*/
|
|
43
|
-
const textNodes = [];
|
|
44
|
-
while (node = walker.nextNode()) {
|
|
45
|
-
if (node.nodeName === '#text') {
|
|
46
|
-
textNodes.push(node.parentElement);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return Array.from(textNodes);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const arr = nativeTreeWalkerFindALLElementHasNodeText();
|
|
53
|
-
|
|
54
|
-
if (arr.length) {
|
|
55
|
-
arr.forEach(value => {
|
|
56
|
-
value['style'].color = color;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// todo end
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* node.style.backgroundColor = color;
|
|
68
|
-
* @param message{{
|
|
69
|
-
* tabId:number,
|
|
70
|
-
* backgroundColor:string
|
|
71
|
-
* }}
|
|
72
|
-
* @returns {Promise<void>}
|
|
73
|
-
*/
|
|
74
|
-
export async function serviceUpdataALLNodeBackgroundColor(message) {
|
|
75
|
-
let {tabId} = message;
|
|
76
|
-
const ass = Object.assign({}, message);
|
|
77
|
-
await browser.scripting.executeScript({
|
|
78
|
-
target: {tabId},
|
|
79
|
-
args: [ass],
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
* @param message{{
|
|
83
|
-
* tabId: number,
|
|
84
|
-
* backgroundColor:string,
|
|
85
|
-
* }}
|
|
86
|
-
* @returns {Promise<void>}
|
|
87
|
-
*/
|
|
88
|
-
func: async (message) => {
|
|
89
|
-
let {backgroundColor} = message;
|
|
90
|
-
updateStyleBackgroundColor(backgroundColor);
|
|
91
|
-
|
|
92
|
-
function updateStyleBackgroundColor(backgroundColor) {
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
* @returns {Node[]}
|
|
96
|
-
*/
|
|
97
|
-
function nativeTreeWalker() {
|
|
98
|
-
const walker = document.createTreeWalker(
|
|
99
|
-
document.body,
|
|
100
|
-
NodeFilter.SHOW_ELEMENT,
|
|
101
|
-
null,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
let node;
|
|
105
|
-
/**
|
|
106
|
-
* @type {Node[]}
|
|
107
|
-
*/
|
|
108
|
-
const textNodes = [];
|
|
109
|
-
while (node = walker.nextNode()) {
|
|
110
|
-
textNodes.push(node);
|
|
111
|
-
}
|
|
112
|
-
return Array.from(textNodes);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @type {Node[]}
|
|
117
|
-
*/
|
|
118
|
-
const arr = nativeTreeWalker();
|
|
119
|
-
|
|
120
|
-
if (arr.length) {
|
|
121
|
-
arr.forEach(value => {
|
|
122
|
-
value['style'].backgroundColor = backgroundColor;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// todo end
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
}
|