@webextkits/messages-center 0.1.2 → 0.1.5
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/dist/background.js +15 -16
- package/dist/contentScript.js +1 -2
- package/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +37 -10
- package/package.json +2 -3
package/dist/background.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var b = (
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
class u {
|
|
1
|
+
var o = Object.defineProperty;
|
|
2
|
+
var b = (a, e, t) => e in a ? o(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var n = (a, e, t) => (b(a, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
class h {
|
|
6
5
|
constructor(e, t) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
n(this, "listeners", {});
|
|
7
|
+
n(this, "tabs", []);
|
|
8
|
+
n(this, "slug");
|
|
9
|
+
n(this, "isDebugger");
|
|
11
10
|
this.slug = e, this.isDebugger = !!t, this.bindMessage(), this.bindEvent();
|
|
12
11
|
}
|
|
13
12
|
on(e, t) {
|
|
@@ -21,14 +20,14 @@ class u {
|
|
|
21
20
|
this.isDebugger && console.log("发送消息", { action: e, payload: t, tabs: this.tabs });
|
|
22
21
|
for (let s of this.tabs)
|
|
23
22
|
try {
|
|
24
|
-
const i = await
|
|
25
|
-
i && i.id ?
|
|
23
|
+
const i = await chrome.tabs.get(s);
|
|
24
|
+
i && i.id ? chrome.tabs.sendMessage(i.id, { from: this.slug, payload: { action: e, payload: t } }) : this.deleteTabById(s);
|
|
26
25
|
} catch (i) {
|
|
27
26
|
console.log(i), this.deleteTabById(s);
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
bindMessage() {
|
|
31
|
-
|
|
30
|
+
chrome.runtime.onMessageExternal.addListener((e, t, s) => {
|
|
32
31
|
var i, r;
|
|
33
32
|
if ((i = t == null ? void 0 : t.tab) != null && i.id) {
|
|
34
33
|
if (this.isDebugger && console.log("收到消息", { request: e, sender: t }), e.action === "__connect")
|
|
@@ -36,14 +35,14 @@ class u {
|
|
|
36
35
|
if (e.action === "__disconnect")
|
|
37
36
|
return this.deleteTabById(t.tab.id), s();
|
|
38
37
|
if (this.listeners[e.action])
|
|
39
|
-
return (r = t == null ? void 0 : t.tab) != null && r.id ? (this.tabs.includes(t.tab.id) || this.tabs.push(t.tab.id), this.listeners[e.action].bind({ request: e, sender: t })(...e.payload).then((
|
|
40
|
-
this.isDebugger && console.log("send to callback from background", { request: e, sender: t, res:
|
|
38
|
+
return (r = t == null ? void 0 : t.tab) != null && r.id ? (this.tabs.includes(t.tab.id) || this.tabs.push(t.tab.id), this.listeners[e.action].bind({ request: e, sender: t })(...e.payload).then((d) => {
|
|
39
|
+
this.isDebugger && console.log("send to callback from background", { request: e, sender: t, res: d }), s(d);
|
|
41
40
|
}), !0) : s();
|
|
42
41
|
}
|
|
43
42
|
});
|
|
44
43
|
}
|
|
45
44
|
bindEvent() {
|
|
46
|
-
|
|
45
|
+
chrome.tabs.onRemoved.addListener((e) => {
|
|
47
46
|
this.deleteTabById(e);
|
|
48
47
|
});
|
|
49
48
|
}
|
|
@@ -55,5 +54,5 @@ class u {
|
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
export {
|
|
58
|
-
|
|
57
|
+
h as MessageInstance
|
|
59
58
|
};
|
package/dist/contentScript.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as r from "webextension-polyfill";
|
|
2
1
|
function n(o, s) {
|
|
3
|
-
|
|
2
|
+
chrome.runtime.onMessage.addListener((e, a) => {
|
|
4
3
|
e.from === o && (s && console.log("received message from background script", e), window.postMessage({ from: e.from, payload: e.payload }));
|
|
5
4
|
});
|
|
6
5
|
}
|
package/dist/hooks.d.ts
CHANGED
package/dist/hooks.js
CHANGED
|
@@ -1,15 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
function l(s, i) {
|
|
2
|
+
if (s === "<all_urls>")
|
|
3
|
+
return /^(https?|file):\/\//.test(i);
|
|
4
|
+
let e;
|
|
5
|
+
try {
|
|
6
|
+
e = new URL(i);
|
|
7
|
+
} catch {
|
|
8
|
+
return !1;
|
|
9
|
+
}
|
|
10
|
+
const c = s.match(/^([^:]+):\/\/([^\/]+)(\/.*)?$/);
|
|
11
|
+
if (!c)
|
|
12
|
+
return !1;
|
|
13
|
+
const [, o, a, r = "/*"] = c;
|
|
14
|
+
if (o === "*") {
|
|
15
|
+
if (e.protocol !== "http:" && e.protocol !== "https:")
|
|
16
|
+
return !1;
|
|
17
|
+
} else if (e.protocol !== `${o}:`)
|
|
18
|
+
return !1;
|
|
19
|
+
return !!function(t, n) {
|
|
20
|
+
if (t === "*")
|
|
21
|
+
return !0;
|
|
22
|
+
if (t.startsWith("*.")) {
|
|
23
|
+
const u = t.slice(2);
|
|
24
|
+
return n === u || n.endsWith("." + u);
|
|
10
25
|
}
|
|
26
|
+
return t === n;
|
|
27
|
+
}(a, e.hostname) && !!function(t, n) {
|
|
28
|
+
const u = t.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
29
|
+
return new RegExp(`^${u}$`, "i").test(n);
|
|
30
|
+
}(r, e.pathname);
|
|
31
|
+
}
|
|
32
|
+
function h(s) {
|
|
33
|
+
const { hostMatch: i, extensionId: e, isDev: c = !1 } = s;
|
|
34
|
+
chrome.tabs.onUpdated.addListener(async (o, a, r) => {
|
|
35
|
+
r && r.url && r && r.url && a && a.status === "loading" && i.some((t) => l(t, r.url)) && chrome.scripting.executeScript({ injectImmediately: !0, world: "MAIN", target: { tabId: o, allFrames: !0 }, func: (t) => {
|
|
36
|
+
window[t.slug] = t;
|
|
37
|
+
}, args: [{ id: chrome.runtime.id, slug: e, isDev: c }] });
|
|
11
38
|
});
|
|
12
39
|
}
|
|
13
40
|
export {
|
|
14
|
-
|
|
41
|
+
h as injectExtensionData
|
|
15
42
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webextkits/messages-center",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./background": "./dist/background.js",
|
|
@@ -34,8 +34,7 @@
|
|
|
34
34
|
"esno": "^0.17.0",
|
|
35
35
|
"glob": "^10.3.10",
|
|
36
36
|
"typescript": "^5.0.2",
|
|
37
|
-
"vite": "^4.4.5"
|
|
38
|
-
"webextension-polyfill": "^0.10.0"
|
|
37
|
+
"vite": "^4.4.5"
|
|
39
38
|
},
|
|
40
39
|
"scripts": {
|
|
41
40
|
"build": "esno ./scripts/build.ts && npm run build:type",
|