@vacantthinker/firefox-addon-framework-easy 2026.528.2339 → 2026.530.1431
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 +3 -0
- package/package.json +1 -1
- package/src/serviceCommon.js +70 -18
- package/src/serviceOpContent.js +1 -1
package/README.md
CHANGED
|
@@ -129,6 +129,9 @@ export async function tabOpRemoveCssCode(tabId, code) { }
|
|
|
129
129
|
|
|
130
130
|
### 📄 File: `src/serviceCommon.js`
|
|
131
131
|
```javascript
|
|
132
|
+
export async function serviceTakeScreenshot(
|
|
133
|
+
{ }
|
|
134
|
+
|
|
132
135
|
export async function serviceElementPicker(message) { }
|
|
133
136
|
|
|
134
137
|
export async function serviceGetFullPageRectData(message) { }
|
package/package.json
CHANGED
package/src/serviceCommon.js
CHANGED
|
@@ -7,7 +7,59 @@ import {
|
|
|
7
7
|
import {browserNotificationCreate} from './browserNotification.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
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
|
+
console.info(tag, `rect=\n`, rect);
|
|
31
|
+
let dataURI = await browser.tabs.captureTab(tabId, {
|
|
32
|
+
rect: rect,
|
|
33
|
+
});
|
|
34
|
+
let assign = Object.assign(
|
|
35
|
+
{},
|
|
36
|
+
{dataURI, filename},
|
|
37
|
+
);
|
|
38
|
+
await browser.scripting.executeScript({
|
|
39
|
+
target: {tabId},
|
|
40
|
+
args: [assign],
|
|
41
|
+
func: function(message) {
|
|
42
|
+
if (message) {
|
|
43
|
+
let {dataURI, filename} = message;
|
|
44
|
+
|
|
45
|
+
imageDataToLocalFile({dataURI, filename});
|
|
46
|
+
|
|
47
|
+
function imageDataToLocalFile({dataURI, filename}) {
|
|
48
|
+
let a = document.createElement('a');
|
|
49
|
+
a.href = dataURI;
|
|
50
|
+
a.download = filename;
|
|
51
|
+
a.click();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// todo end if(message)
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* middle ware, output => {rect, uniqueSelector,}
|
|
11
63
|
* @param message{{
|
|
12
64
|
* tabId:number,
|
|
13
65
|
* act:string
|
|
@@ -79,14 +131,16 @@ export async function serviceElementPicker(message) {
|
|
|
79
131
|
if (target.id === overlayId) return;
|
|
80
132
|
|
|
81
133
|
// Get exact coordinates of the hovered element
|
|
82
|
-
const
|
|
134
|
+
const clientRect = target.getBoundingClientRect();
|
|
83
135
|
|
|
84
136
|
// Move the floating overlay exactly over the target
|
|
85
137
|
overlay.style.setProperty('display', 'block', 'important');
|
|
86
|
-
overlay.style.setProperty('top', `${
|
|
87
|
-
overlay.style.setProperty('left', `${
|
|
88
|
-
overlay.style.setProperty('width', `${
|
|
89
|
-
|
|
138
|
+
overlay.style.setProperty('top', `${clientRect.top}px`, 'important');
|
|
139
|
+
overlay.style.setProperty('left', `${clientRect.left}px`, 'important');
|
|
140
|
+
overlay.style.setProperty('width', `${clientRect.width}px`,
|
|
141
|
+
'important');
|
|
142
|
+
overlay.style.setProperty('height', `${clientRect.height}px`,
|
|
143
|
+
'important');
|
|
90
144
|
|
|
91
145
|
// Change mouse cursor to indicate picking mode
|
|
92
146
|
document.body.style.setProperty('cursor', 'crosshair', 'important');
|
|
@@ -102,21 +156,19 @@ export async function serviceElementPicker(message) {
|
|
|
102
156
|
stopPickingMode();
|
|
103
157
|
|
|
104
158
|
// Calculate screenshot coordinates
|
|
105
|
-
let
|
|
106
|
-
let
|
|
107
|
-
height:
|
|
108
|
-
width:
|
|
109
|
-
x:
|
|
110
|
-
y:
|
|
159
|
+
let clientRect = target.getBoundingClientRect();
|
|
160
|
+
let rect = {
|
|
161
|
+
height: clientRect.height,
|
|
162
|
+
width: clientRect.width,
|
|
163
|
+
x: clientRect.left + window.scrollX,
|
|
164
|
+
y: clientRect.top + window.scrollY,
|
|
111
165
|
};
|
|
112
166
|
|
|
113
|
-
console.log('Target Selected:', {rectData});
|
|
114
|
-
|
|
115
167
|
// Assuming 'target' is your clicked element (e.g., from e.target)
|
|
116
168
|
let messageTakeScreenshot = Object.assign(
|
|
117
169
|
{}, // Start with a fresh, empty object
|
|
118
170
|
message, // Put the original message first so it doesn't overwrite your new data
|
|
119
|
-
{
|
|
171
|
+
{rect},
|
|
120
172
|
{
|
|
121
173
|
// The guaranteed unique CSS path (e.g., "div#wrap > ul > li:nth-of-type(2)")
|
|
122
174
|
uniqueSelector: getUniqueSelector(target),
|
|
@@ -151,7 +203,7 @@ export async function serviceElementPicker(message) {
|
|
|
151
203
|
}
|
|
152
204
|
|
|
153
205
|
/**
|
|
154
|
-
* middle ware, output: {
|
|
206
|
+
* middle ware, output: {rect}
|
|
155
207
|
*
|
|
156
208
|
* @param message{{
|
|
157
209
|
* tabId:number,
|
|
@@ -170,13 +222,13 @@ export async function serviceGetFullPageRectData(message) {
|
|
|
170
222
|
let x = 0, y = 0;
|
|
171
223
|
let width = document.documentElement.scrollWidth;
|
|
172
224
|
let height = document.documentElement.scrollHeight;
|
|
173
|
-
let
|
|
225
|
+
let rect = {
|
|
174
226
|
x, y, width, height,
|
|
175
227
|
};
|
|
176
228
|
browser.runtime.sendMessage(Object.assign(
|
|
177
229
|
{},
|
|
178
230
|
message,
|
|
179
|
-
{
|
|
231
|
+
{rect},
|
|
180
232
|
));
|
|
181
233
|
// todo end if (message)
|
|
182
234
|
},
|
package/src/serviceOpContent.js
CHANGED
|
@@ -79,7 +79,7 @@ export function serviceRemoveIllegalWord(value) {
|
|
|
79
79
|
// 2. Use Unicode properties to remove all punctuation (\p{P}) and all symbols/geometry (\p{S})
|
|
80
80
|
// This natively crushes Chinese full-width punctuation, em dashes (—), Emojis, math symbols, and special brackets.
|
|
81
81
|
// Note: The 'u' flag is mandatory to enable Unicode mode in the regex.
|
|
82
|
-
name = name.replace(/[\p{P}\p{S}]/gu, ' ');
|
|
82
|
+
name = name.replace(/[\p{P}\p{S}\p{C}]/gu, ' ');
|
|
83
83
|
|
|
84
84
|
// 3. Additional defense: Filter out hidden control characters that Firefox/OS are extremely sensitive to (0-31 and 127-159)
|
|
85
85
|
name = name.replace(/[\x00-\x1F\x7F-\x9F]/g, ' ');
|