chrome-extension-tools
Advanced tools
Comparing version
1200
dist/index.js
@@ -1,38 +0,38 @@ | ||
function Dt() { | ||
const r = window; | ||
function t() { | ||
function n(l, c) { | ||
return function(...d) { | ||
var $, p; | ||
l === "open" && (this.open_args = d); | ||
const g = c[l]; | ||
if (g != null && g.callback) { | ||
const E = g.callback.call(this, d, this.xhr); | ||
if (E !== void 0) | ||
return E; | ||
function Pt() { | ||
const n = window; | ||
function e() { | ||
function s(d, c) { | ||
return function(...g) { | ||
var E, C; | ||
d === "open" && (this.open_args = g); | ||
const m = c[d]; | ||
if (m != null && m.callback) { | ||
const I = m.callback.call(this, g, this.xhr); | ||
if (I !== void 0) | ||
return I; | ||
} | ||
return (p = ($ = this.xhr)[l]) == null ? void 0 : p.call($, ...d); | ||
return (C = (E = this.xhr)[d]) == null ? void 0 : C.call(E, ...g); | ||
}; | ||
} | ||
function i(l, c) { | ||
function r(d, c) { | ||
return function() { | ||
const d = Object.prototype.hasOwnProperty.call(this, `${l}_`) ? this[`${l}_`] : this.xhr[l], g = c[l]; | ||
return g != null && g.getter ? g.getter(d, this) : d; | ||
const g = Object.prototype.hasOwnProperty.call(this, `${d}_`) ? this[`${d}_`] : this.xhr[d], m = c[d]; | ||
return m != null && m.getter ? m.getter(g, this) : g; | ||
}; | ||
} | ||
function T(l, c) { | ||
return function(d) { | ||
const g = this.xhr, $ = c[l]; | ||
if (this[`${l}_`] = d, l.startsWith("on")) { | ||
const p = l; | ||
typeof d == "function" ? g[p] = (E) => { | ||
var N; | ||
((N = $ == null ? void 0 : $.callback) == null ? void 0 : N.call(this, [E], g)) !== !0 && d.call(this, E); | ||
} : g[p] = null; | ||
function h(d, c) { | ||
return function(g) { | ||
const m = this.xhr, E = c[d]; | ||
if (this[`${d}_`] = g, d.startsWith("on")) { | ||
const C = d; | ||
typeof g == "function" ? m[C] = (I) => { | ||
var U; | ||
((U = E == null ? void 0 : E.callback) == null ? void 0 : U.call(this, [I], m)) !== !0 && g.call(this, I); | ||
} : m[C] = null; | ||
} else { | ||
const p = $ != null && $.setter ? $.setter(d, this) : d; | ||
const C = E != null && E.setter ? E.setter(g, this) : g; | ||
try { | ||
g[l] = p; | ||
m[d] = C; | ||
} catch { | ||
console.warn(`xhr的${l}属性不可写`); | ||
console.warn(`xhr的${d}属性不可写`); | ||
} | ||
@@ -42,17 +42,17 @@ } | ||
} | ||
function h(l) { | ||
return r.realXhr = r.realXhr || XMLHttpRequest, XMLHttpRequest = function() { | ||
const c = new r.realXhr(); | ||
function l(d) { | ||
return n.realXhr = n.realXhr || XMLHttpRequest, XMLHttpRequest = function() { | ||
const c = new n.realXhr(); | ||
this.xhr = c; | ||
for (const d in c) | ||
typeof c[d] == "function" ? this[d] = n(d, l) : Object.defineProperty(this, d, { | ||
get: i(d, l), | ||
set: T(d, l), | ||
for (const g in c) | ||
typeof c[g] == "function" ? this[g] = s(g, d) : Object.defineProperty(this, g, { | ||
get: r(g, d), | ||
set: h(g, d), | ||
enumerable: !0 | ||
}); | ||
}, r.realXhr; | ||
}, n.realXhr; | ||
} | ||
h({ | ||
l({ | ||
open: { | ||
callback(l, c) { | ||
callback(d, c) { | ||
} | ||
@@ -62,7 +62,7 @@ }, | ||
// @ts-ignore | ||
callback(l, c) { | ||
var d, g; | ||
e({ | ||
url: (d = c.open_args) == null ? void 0 : d[1], | ||
method: (g = c.open_args) == null ? void 0 : g[0], | ||
callback(d, c) { | ||
var g, m; | ||
t({ | ||
url: (g = c.open_args) == null ? void 0 : g[1], | ||
method: (m = c.open_args) == null ? void 0 : m[0], | ||
response: c.response, | ||
@@ -75,7 +75,7 @@ requestType: "xhr-onload" | ||
// @ts-ignore | ||
callback(l, c) { | ||
var d, g; | ||
(c == null ? void 0 : c.readyState) === 4 && e({ | ||
url: (d = c.open_args) == null ? void 0 : d[1], | ||
method: (g = c.open_args) == null ? void 0 : g[0], | ||
callback(d, c) { | ||
var g, m; | ||
(c == null ? void 0 : c.readyState) === 4 && t({ | ||
url: (g = c.open_args) == null ? void 0 : g[1], | ||
method: (m = c.open_args) == null ? void 0 : m[0], | ||
response: c.response, | ||
@@ -88,7 +88,7 @@ requestType: "xhr-onreadystatechange" | ||
// @ts-ignore | ||
callback(l, c) { | ||
var d, g; | ||
e({ | ||
url: (d = c.open_args) == null ? void 0 : d[1], | ||
method: (g = c.open_args) == null ? void 0 : g[0], | ||
callback(d, c) { | ||
var g, m; | ||
t({ | ||
url: (g = c.open_args) == null ? void 0 : g[1], | ||
method: (m = c.open_args) == null ? void 0 : m[0], | ||
response: c.response, | ||
@@ -100,88 +100,88 @@ requestType: "xhr-onloadend" | ||
}); | ||
const b = window.fetch.bind(window); | ||
window.fetch = function(l, c) { | ||
const d = l instanceof Request ? l.url : l.toString(); | ||
return b(l, c).then((g) => { | ||
var p; | ||
const $ = g.clone(); | ||
return (p = $.headers.get("Content-Type")) != null && p.includes("application/json") && $.json().then((E) => { | ||
e({ | ||
url: d, | ||
const p = window.fetch.bind(window); | ||
window.fetch = function(d, c) { | ||
const g = d instanceof Request ? d.url : d.toString(); | ||
return p(d, c).then((m) => { | ||
var C; | ||
const E = m.clone(); | ||
return (C = E.headers.get("Content-Type")) != null && C.includes("application/json") && E.json().then((I) => { | ||
t({ | ||
url: g, | ||
method: c == null ? void 0 : c.method, | ||
response: E, | ||
response: I, | ||
requestType: "fetch" | ||
}); | ||
}), g; | ||
}), m; | ||
}); | ||
}, console.log("inject ok"); | ||
} | ||
function e(n) { | ||
function t(s) { | ||
window.postMessage({ | ||
type: "CS2SP_GET_REQUEST", | ||
data: n | ||
data: s | ||
}); | ||
} | ||
t(); | ||
e(); | ||
} | ||
function St(r) { | ||
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; | ||
function St(n) { | ||
return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n; | ||
} | ||
var tt = { exports: {} }, Tt = tt.exports, it; | ||
var tt = { exports: {} }, Tt = tt.exports, ct; | ||
function yt() { | ||
return it || (it = 1, function(r, t) { | ||
(function(e, n) { | ||
r.exports = n(); | ||
return ct || (ct = 1, function(n, e) { | ||
(function(t, s) { | ||
n.exports = s(); | ||
})(Tt, function() { | ||
var e = 1e3, n = 6e4, i = 36e5, T = "millisecond", h = "second", b = "minute", l = "hour", c = "day", d = "week", g = "month", $ = "quarter", p = "year", E = "date", P = "Invalid Date", N = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, Q = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, G = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(f) { | ||
var o = ["th", "st", "nd", "rd"], s = f % 100; | ||
return "[" + f + (o[(s - 20) % 10] || o[s] || o[0]) + "]"; | ||
} }, j = function(f, o, s) { | ||
var t = 1e3, s = 6e4, r = 36e5, h = "millisecond", l = "second", p = "minute", d = "hour", c = "day", g = "week", m = "month", E = "quarter", C = "year", I = "date", D = "Invalid Date", U = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, Q = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, B = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(f) { | ||
var o = ["th", "st", "nd", "rd"], i = f % 100; | ||
return "[" + f + (o[(i - 20) % 10] || o[i] || o[0]) + "]"; | ||
} }, q = function(f, o, i) { | ||
var u = String(f); | ||
return !u || u.length >= o ? f : "" + Array(o + 1 - u.length).join(s) + f; | ||
}, mt = { s: j, z: function(f) { | ||
var o = -f.utcOffset(), s = Math.abs(o), u = Math.floor(s / 60), a = s % 60; | ||
return (o <= 0 ? "+" : "-") + j(u, 2, "0") + ":" + j(a, 2, "0"); | ||
}, m: function f(o, s) { | ||
if (o.date() < s.date()) return -f(s, o); | ||
var u = 12 * (s.year() - o.year()) + (s.month() - o.month()), a = o.clone().add(u, g), m = s - a < 0, S = o.clone().add(u + (m ? -1 : 1), g); | ||
return +(-(u + (s - a) / (m ? a - S : S - a)) || 0); | ||
return !u || u.length >= o ? f : "" + Array(o + 1 - u.length).join(i) + f; | ||
}, mt = { s: q, z: function(f) { | ||
var o = -f.utcOffset(), i = Math.abs(o), u = Math.floor(i / 60), a = i % 60; | ||
return (o <= 0 ? "+" : "-") + q(u, 2, "0") + ":" + q(a, 2, "0"); | ||
}, m: function f(o, i) { | ||
if (o.date() < i.date()) return -f(i, o); | ||
var u = 12 * (i.year() - o.year()) + (i.month() - o.month()), a = o.clone().add(u, m), S = i - a < 0, T = o.clone().add(u + (S ? -1 : 1), m); | ||
return +(-(u + (i - a) / (S ? a - T : T - a)) || 0); | ||
}, a: function(f) { | ||
return f < 0 ? Math.ceil(f) || 0 : Math.floor(f); | ||
}, p: function(f) { | ||
return { M: g, y: p, w: d, d: c, D: E, h: l, m: b, s: h, ms: T, Q: $ }[f] || String(f || "").toLowerCase().replace(/s$/, ""); | ||
return { M: m, y: C, w: g, d: c, D: I, h: d, m: p, s: l, ms: h, Q: E }[f] || String(f || "").toLowerCase().replace(/s$/, ""); | ||
}, u: function(f) { | ||
return f === void 0; | ||
} }, H = "en", U = {}; | ||
U[H] = G; | ||
var rt = "$isDayjsObject", nt = function(f) { | ||
return f instanceof K || !(!f || !f[rt]); | ||
}, J = function f(o, s, u) { | ||
} }, Y = "en", A = {}; | ||
A[Y] = B; | ||
var at = "$isDayjsObject", st = function(f) { | ||
return f instanceof K || !(!f || !f[at]); | ||
}, J = function f(o, i, u) { | ||
var a; | ||
if (!o) return H; | ||
if (!o) return Y; | ||
if (typeof o == "string") { | ||
var m = o.toLowerCase(); | ||
U[m] && (a = m), s && (U[m] = s, a = m); | ||
var S = o.split("-"); | ||
if (!a && S.length > 1) return f(S[0]); | ||
var S = o.toLowerCase(); | ||
A[S] && (a = S), i && (A[S] = i, a = S); | ||
var T = o.split("-"); | ||
if (!a && T.length > 1) return f(T[0]); | ||
} else { | ||
var C = o.name; | ||
U[C] = o, a = C; | ||
var b = o.name; | ||
A[b] = o, a = b; | ||
} | ||
return !u && a && (H = a), a || !u && H; | ||
}, R = function(f, o) { | ||
if (nt(f)) return f.clone(); | ||
var s = typeof o == "object" ? o : {}; | ||
return s.date = f, s.args = arguments, new K(s); | ||
return !u && a && (Y = a), a || !u && Y; | ||
}, $ = function(f, o) { | ||
if (st(f)) return f.clone(); | ||
var i = typeof o == "object" ? o : {}; | ||
return i.date = f, i.args = arguments, new K(i); | ||
}, y = mt; | ||
y.l = J, y.i = nt, y.w = function(f, o) { | ||
return R(f, { locale: o.$L, utc: o.$u, x: o.$x, $offset: o.$offset }); | ||
y.l = J, y.i = st, y.w = function(f, o) { | ||
return $(f, { locale: o.$L, utc: o.$u, x: o.$x, $offset: o.$offset }); | ||
}; | ||
var K = function() { | ||
function f(s) { | ||
this.$L = J(s.locale, null, !0), this.parse(s), this.$x = this.$x || s.x || {}, this[rt] = !0; | ||
function f(i) { | ||
this.$L = J(i.locale, null, !0), this.parse(i), this.$x = this.$x || i.x || {}, this[at] = !0; | ||
} | ||
var o = f.prototype; | ||
return o.parse = function(s) { | ||
return o.parse = function(i) { | ||
this.$d = function(u) { | ||
var a = u.date, m = u.utc; | ||
var a = u.date, S = u.utc; | ||
if (a === null) return /* @__PURE__ */ new Date(NaN); | ||
@@ -191,26 +191,26 @@ if (y.u(a)) return /* @__PURE__ */ new Date(); | ||
if (typeof a == "string" && !/Z$/i.test(a)) { | ||
var S = a.match(N); | ||
if (S) { | ||
var C = S[2] - 1 || 0, _ = (S[7] || "0").substring(0, 3); | ||
return m ? new Date(Date.UTC(S[1], C, S[3] || 1, S[4] || 0, S[5] || 0, S[6] || 0, _)) : new Date(S[1], C, S[3] || 1, S[4] || 0, S[5] || 0, S[6] || 0, _); | ||
var T = a.match(U); | ||
if (T) { | ||
var b = T[2] - 1 || 0, _ = (T[7] || "0").substring(0, 3); | ||
return S ? new Date(Date.UTC(T[1], b, T[3] || 1, T[4] || 0, T[5] || 0, T[6] || 0, _)) : new Date(T[1], b, T[3] || 1, T[4] || 0, T[5] || 0, T[6] || 0, _); | ||
} | ||
} | ||
return new Date(a); | ||
}(s), this.init(); | ||
}(i), this.init(); | ||
}, o.init = function() { | ||
var s = this.$d; | ||
this.$y = s.getFullYear(), this.$M = s.getMonth(), this.$D = s.getDate(), this.$W = s.getDay(), this.$H = s.getHours(), this.$m = s.getMinutes(), this.$s = s.getSeconds(), this.$ms = s.getMilliseconds(); | ||
var i = this.$d; | ||
this.$y = i.getFullYear(), this.$M = i.getMonth(), this.$D = i.getDate(), this.$W = i.getDay(), this.$H = i.getHours(), this.$m = i.getMinutes(), this.$s = i.getSeconds(), this.$ms = i.getMilliseconds(); | ||
}, o.$utils = function() { | ||
return y; | ||
}, o.isValid = function() { | ||
return this.$d.toString() !== P; | ||
}, o.isSame = function(s, u) { | ||
var a = R(s); | ||
return this.$d.toString() !== D; | ||
}, o.isSame = function(i, u) { | ||
var a = $(i); | ||
return this.startOf(u) <= a && a <= this.endOf(u); | ||
}, o.isAfter = function(s, u) { | ||
return R(s) < this.startOf(u); | ||
}, o.isBefore = function(s, u) { | ||
return this.endOf(u) < R(s); | ||
}, o.$g = function(s, u, a) { | ||
return y.u(s) ? this[u] : this.set(a, s); | ||
}, o.isAfter = function(i, u) { | ||
return $(i) < this.startOf(u); | ||
}, o.isBefore = function(i, u) { | ||
return this.endOf(u) < $(i); | ||
}, o.$g = function(i, u, a) { | ||
return y.u(i) ? this[u] : this.set(a, i); | ||
}, o.unix = function() { | ||
@@ -220,71 +220,71 @@ return Math.floor(this.valueOf() / 1e3); | ||
return this.$d.getTime(); | ||
}, o.startOf = function(s, u) { | ||
var a = this, m = !!y.u(u) || u, S = y.p(s), C = function(F, v) { | ||
var O = y.w(a.$u ? Date.UTC(a.$y, v, F) : new Date(a.$y, v, F), a); | ||
return m ? O : O.endOf(c); | ||
}, _ = function(F, v) { | ||
return y.w(a.toDate()[F].apply(a.toDate("s"), (m ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(v)), a); | ||
}, w = this.$W, I = this.$M, B = this.$D, q = "set" + (this.$u ? "UTC" : ""); | ||
switch (S) { | ||
case p: | ||
return m ? C(1, 0) : C(31, 11); | ||
}, o.startOf = function(i, u) { | ||
var a = this, S = !!y.u(u) || u, T = y.p(i), b = function(j, G) { | ||
var x = y.w(a.$u ? Date.UTC(a.$y, G, j) : new Date(a.$y, G, j), a); | ||
return S ? x : x.endOf(c); | ||
}, _ = function(j, G) { | ||
return y.w(a.toDate()[j].apply(a.toDate("s"), (S ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(G)), a); | ||
}, M = this.$W, R = this.$M, k = this.$D, H = "set" + (this.$u ? "UTC" : ""); | ||
switch (T) { | ||
case C: | ||
return S ? b(1, 0) : b(31, 11); | ||
case m: | ||
return S ? b(1, R) : b(0, R + 1); | ||
case g: | ||
return m ? C(1, I) : C(0, I + 1); | ||
var F = this.$locale().weekStart || 0, W = (M < F ? M + 7 : M) - F; | ||
return b(S ? k - W : k + (6 - W), R); | ||
case c: | ||
case I: | ||
return _(H + "Hours", 0); | ||
case d: | ||
var A = this.$locale().weekStart || 0, Y = (w < A ? w + 7 : w) - A; | ||
return C(m ? B - Y : B + (6 - Y), I); | ||
case c: | ||
case E: | ||
return _(q + "Hours", 0); | ||
return _(H + "Minutes", 1); | ||
case p: | ||
return _(H + "Seconds", 2); | ||
case l: | ||
return _(q + "Minutes", 1); | ||
case b: | ||
return _(q + "Seconds", 2); | ||
case h: | ||
return _(q + "Milliseconds", 3); | ||
return _(H + "Milliseconds", 3); | ||
default: | ||
return this.clone(); | ||
} | ||
}, o.endOf = function(s) { | ||
return this.startOf(s, !1); | ||
}, o.$set = function(s, u) { | ||
var a, m = y.p(s), S = "set" + (this.$u ? "UTC" : ""), C = (a = {}, a[c] = S + "Date", a[E] = S + "Date", a[g] = S + "Month", a[p] = S + "FullYear", a[l] = S + "Hours", a[b] = S + "Minutes", a[h] = S + "Seconds", a[T] = S + "Milliseconds", a)[m], _ = m === c ? this.$D + (u - this.$W) : u; | ||
if (m === g || m === p) { | ||
var w = this.clone().set(E, 1); | ||
w.$d[C](_), w.init(), this.$d = w.set(E, Math.min(this.$D, w.daysInMonth())).$d; | ||
} else C && this.$d[C](_); | ||
}, o.endOf = function(i) { | ||
return this.startOf(i, !1); | ||
}, o.$set = function(i, u) { | ||
var a, S = y.p(i), T = "set" + (this.$u ? "UTC" : ""), b = (a = {}, a[c] = T + "Date", a[I] = T + "Date", a[m] = T + "Month", a[C] = T + "FullYear", a[d] = T + "Hours", a[p] = T + "Minutes", a[l] = T + "Seconds", a[h] = T + "Milliseconds", a)[S], _ = S === c ? this.$D + (u - this.$W) : u; | ||
if (S === m || S === C) { | ||
var M = this.clone().set(I, 1); | ||
M.$d[b](_), M.init(), this.$d = M.set(I, Math.min(this.$D, M.daysInMonth())).$d; | ||
} else b && this.$d[b](_); | ||
return this.init(), this; | ||
}, o.set = function(s, u) { | ||
return this.clone().$set(s, u); | ||
}, o.get = function(s) { | ||
return this[y.p(s)](); | ||
}, o.add = function(s, u) { | ||
var a, m = this; | ||
s = Number(s); | ||
var S = y.p(u), C = function(I) { | ||
var B = R(m); | ||
return y.w(B.date(B.date() + Math.round(I * s)), m); | ||
}, o.set = function(i, u) { | ||
return this.clone().$set(i, u); | ||
}, o.get = function(i) { | ||
return this[y.p(i)](); | ||
}, o.add = function(i, u) { | ||
var a, S = this; | ||
i = Number(i); | ||
var T = y.p(u), b = function(R) { | ||
var k = $(S); | ||
return y.w(k.date(k.date() + Math.round(R * i)), S); | ||
}; | ||
if (S === g) return this.set(g, this.$M + s); | ||
if (S === p) return this.set(p, this.$y + s); | ||
if (S === c) return C(1); | ||
if (S === d) return C(7); | ||
var _ = (a = {}, a[b] = n, a[l] = i, a[h] = e, a)[S] || 1, w = this.$d.getTime() + s * _; | ||
return y.w(w, this); | ||
}, o.subtract = function(s, u) { | ||
return this.add(-1 * s, u); | ||
}, o.format = function(s) { | ||
if (T === m) return this.set(m, this.$M + i); | ||
if (T === C) return this.set(C, this.$y + i); | ||
if (T === c) return b(1); | ||
if (T === g) return b(7); | ||
var _ = (a = {}, a[p] = s, a[d] = r, a[l] = t, a)[T] || 1, M = this.$d.getTime() + i * _; | ||
return y.w(M, this); | ||
}, o.subtract = function(i, u) { | ||
return this.add(-1 * i, u); | ||
}, o.format = function(i) { | ||
var u = this, a = this.$locale(); | ||
if (!this.isValid()) return a.invalidDate || P; | ||
var m = s || "YYYY-MM-DDTHH:mm:ssZ", S = y.z(this), C = this.$H, _ = this.$m, w = this.$M, I = a.weekdays, B = a.months, q = a.meridiem, A = function(v, O, W, V) { | ||
return v && (v[O] || v(u, m)) || W[O].slice(0, V); | ||
}, Y = function(v) { | ||
return y.s(C % 12 || 12, v, "0"); | ||
}, F = q || function(v, O, W) { | ||
var V = v < 12 ? "AM" : "PM"; | ||
return W ? V.toLowerCase() : V; | ||
if (!this.isValid()) return a.invalidDate || D; | ||
var S = i || "YYYY-MM-DDTHH:mm:ssZ", T = y.z(this), b = this.$H, _ = this.$m, M = this.$M, R = a.weekdays, k = a.months, H = a.meridiem, F = function(G, x, X, V) { | ||
return G && (G[x] || G(u, S)) || X[x].slice(0, V); | ||
}, W = function(G) { | ||
return y.s(b % 12 || 12, G, "0"); | ||
}, j = H || function(G, x, X) { | ||
var V = G < 12 ? "AM" : "PM"; | ||
return X ? V.toLowerCase() : V; | ||
}; | ||
return m.replace(Q, function(v, O) { | ||
return O || function(W) { | ||
switch (W) { | ||
return S.replace(Q, function(G, x) { | ||
return x || function(X) { | ||
switch (X) { | ||
case "YY": | ||
@@ -295,9 +295,9 @@ return String(u.$y).slice(-2); | ||
case "M": | ||
return w + 1; | ||
return M + 1; | ||
case "MM": | ||
return y.s(w + 1, 2, "0"); | ||
return y.s(M + 1, 2, "0"); | ||
case "MMM": | ||
return A(a.monthsShort, w, B, 3); | ||
return F(a.monthsShort, M, k, 3); | ||
case "MMMM": | ||
return A(B, w); | ||
return F(k, M); | ||
case "D": | ||
@@ -310,19 +310,19 @@ return u.$D; | ||
case "dd": | ||
return A(a.weekdaysMin, u.$W, I, 2); | ||
return F(a.weekdaysMin, u.$W, R, 2); | ||
case "ddd": | ||
return A(a.weekdaysShort, u.$W, I, 3); | ||
return F(a.weekdaysShort, u.$W, R, 3); | ||
case "dddd": | ||
return I[u.$W]; | ||
return R[u.$W]; | ||
case "H": | ||
return String(C); | ||
return String(b); | ||
case "HH": | ||
return y.s(C, 2, "0"); | ||
return y.s(b, 2, "0"); | ||
case "h": | ||
return Y(1); | ||
return W(1); | ||
case "hh": | ||
return Y(2); | ||
return W(2); | ||
case "a": | ||
return F(C, _, !0); | ||
return j(b, _, !0); | ||
case "A": | ||
return F(C, _, !1); | ||
return j(b, _, !1); | ||
case "m": | ||
@@ -339,50 +339,50 @@ return String(_); | ||
case "Z": | ||
return S; | ||
return T; | ||
} | ||
return null; | ||
}(v) || S.replace(":", ""); | ||
}(G) || T.replace(":", ""); | ||
}); | ||
}, o.utcOffset = function() { | ||
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15); | ||
}, o.diff = function(s, u, a) { | ||
var m, S = this, C = y.p(u), _ = R(s), w = (_.utcOffset() - this.utcOffset()) * n, I = this - _, B = function() { | ||
return y.m(S, _); | ||
}, o.diff = function(i, u, a) { | ||
var S, T = this, b = y.p(u), _ = $(i), M = (_.utcOffset() - this.utcOffset()) * s, R = this - _, k = function() { | ||
return y.m(T, _); | ||
}; | ||
switch (C) { | ||
case p: | ||
m = B() / 12; | ||
switch (b) { | ||
case C: | ||
S = k() / 12; | ||
break; | ||
case m: | ||
S = k(); | ||
break; | ||
case E: | ||
S = k() / 3; | ||
break; | ||
case g: | ||
m = B(); | ||
S = (R - M) / 6048e5; | ||
break; | ||
case $: | ||
m = B() / 3; | ||
case c: | ||
S = (R - M) / 864e5; | ||
break; | ||
case d: | ||
m = (I - w) / 6048e5; | ||
S = R / r; | ||
break; | ||
case c: | ||
m = (I - w) / 864e5; | ||
case p: | ||
S = R / s; | ||
break; | ||
case l: | ||
m = I / i; | ||
S = R / t; | ||
break; | ||
case b: | ||
m = I / n; | ||
break; | ||
case h: | ||
m = I / e; | ||
break; | ||
default: | ||
m = I; | ||
S = R; | ||
} | ||
return a ? m : y.a(m); | ||
return a ? S : y.a(S); | ||
}, o.daysInMonth = function() { | ||
return this.endOf(g).$D; | ||
return this.endOf(m).$D; | ||
}, o.$locale = function() { | ||
return U[this.$L]; | ||
}, o.locale = function(s, u) { | ||
if (!s) return this.$L; | ||
var a = this.clone(), m = J(s, u, !0); | ||
return m && (a.$L = m), a; | ||
return A[this.$L]; | ||
}, o.locale = function(i, u) { | ||
if (!i) return this.$L; | ||
var a = this.clone(), S = J(i, u, !0); | ||
return S && (a.$L = S), a; | ||
}, o.clone = function() { | ||
@@ -399,17 +399,17 @@ return y.w(this.$d, this); | ||
}, f; | ||
}(), st = K.prototype; | ||
return R.prototype = st, [["$ms", T], ["$s", h], ["$m", b], ["$H", l], ["$W", c], ["$M", g], ["$y", p], ["$D", E]].forEach(function(f) { | ||
st[f[1]] = function(o) { | ||
}(), ot = K.prototype; | ||
return $.prototype = ot, [["$ms", h], ["$s", l], ["$m", p], ["$H", d], ["$W", c], ["$M", m], ["$y", C], ["$D", I]].forEach(function(f) { | ||
ot[f[1]] = function(o) { | ||
return this.$g(o, f[0], f[1]); | ||
}; | ||
}), R.extend = function(f, o) { | ||
return f.$i || (f(o, K, R), f.$i = !0), R; | ||
}, R.locale = J, R.isDayjs = nt, R.unix = function(f) { | ||
return R(1e3 * f); | ||
}, R.en = U[H], R.Ls = U, R.p = {}, R; | ||
}), $.extend = function(f, o) { | ||
return f.$i || (f(o, K, $), f.$i = !0), $; | ||
}, $.locale = J, $.isDayjs = st, $.unix = function(f) { | ||
return $(1e3 * f); | ||
}, $.en = A[Y], $.Ls = A, $.p = {}, $; | ||
}); | ||
}(tt)), tt.exports; | ||
} | ||
var Ct = yt(); | ||
const pt = /* @__PURE__ */ St(Ct), L = { | ||
var bt = yt(); | ||
const Ct = /* @__PURE__ */ St(bt), v = { | ||
SP2CS_EXECUTE_TASK: "CET_SP2CS_EXECUTE_TASK", | ||
@@ -424,28 +424,126 @@ SP2BG_GET_CURRENT_TAB: "CET_SP2BG_GET_CURRENT_TAB", | ||
SP2BG_LOG: "SP2BG_LOG" | ||
}, z = { | ||
}, P = { | ||
debug: !1 | ||
}; | ||
function Pt(r) { | ||
z.debug = r; | ||
function Ot(n) { | ||
P.debug = n; | ||
} | ||
var x = /* @__PURE__ */ ((r) => (r.CS = "cs", r.SP = "sp", r.BG = "bg", r))(x || {}), M = /* @__PURE__ */ ((r) => (r.DEBUG = "debug", r.INFO = "info", r.WARN = "warn", r.ERROR = "error", r))(M || {}); | ||
const at = []; | ||
function Z(r, t) { | ||
const e = at.find((n) => n.messageId === r); | ||
e ? (console.warn("已经监听过相关事件,覆盖旧事件"), e.bgCallback = t) : at.push({ | ||
messageId: r, | ||
bgCallback: t | ||
var L = /* @__PURE__ */ ((n) => (n.CS = "cs", n.SP = "sp", n.BG = "bg", n))(L || {}), w = /* @__PURE__ */ ((n) => (n.DEBUG = "debug", n.INFO = "info", n.WARN = "warn", n.ERROR = "error", n))(w || {}); | ||
const rt = []; | ||
function _t(n, e, t) { | ||
if (!t) | ||
throw new Error("option is required"); | ||
return P.debug && console.log("stat sendMsgByBG", n, e, t), new Promise((s) => { | ||
if (t.destination === L.CS) { | ||
if (!t.tabId) { | ||
console.error("tabId is required"); | ||
return; | ||
} | ||
chrome.tabs.sendMessage(t.tabId, { | ||
messageId: n, | ||
data: e, | ||
option: t | ||
}, (r) => { | ||
P.debug && console.log("sendMsgByBG response2", r), s({ | ||
data: r == null ? void 0 : r.data, | ||
messageId: n, | ||
tabId: t.tabId, | ||
success: (r == null ? void 0 : r.success) || !1, | ||
msg: r == null ? void 0 : r.msg | ||
}); | ||
}); | ||
} else | ||
chrome.runtime.sendMessage({ | ||
messageId: n, | ||
data: e, | ||
option: t | ||
}, (r) => { | ||
P.debug && console.log("sendMsgByBG response", r), s({ | ||
data: r == null ? void 0 : r.data, | ||
messageId: n, | ||
tabId: t.tabId, | ||
success: (r == null ? void 0 : r.success) || !1, | ||
msg: r == null ? void 0 : r.msg | ||
}); | ||
}); | ||
}); | ||
} | ||
const ot = []; | ||
function et(r, t, e) { | ||
return new Promise((n) => { | ||
z.debug && console.log("cs sendMsgByCS", r, t, e), chrome.runtime.sendMessage({ messageId: r, data: t, option: e }, {}, (i) => { | ||
z.debug && console.log("cs sendMsgByCS response", r, i), n({ | ||
data: i == null ? void 0 : i.data, | ||
tabId: e.tabId, | ||
tabUrl: e.tabUrl, | ||
messageId: r, | ||
success: (i == null ? void 0 : i.success) || !1, | ||
msg: i == null ? void 0 : i.msg | ||
function Z(n, e) { | ||
const t = rt.find((s) => s.messageId === n); | ||
t ? (console.warn("已经监听过相关事件,覆盖旧事件"), t.bgCallback = e) : rt.push({ | ||
messageId: n, | ||
bgCallback: e | ||
}); | ||
} | ||
function Dt() { | ||
chrome.runtime.onMessage.addListener( | ||
(n, e, t) => { | ||
if (P.debug && console.log("bg receive", n, e), Object.prototype.toString.call(n) !== "[object Object]" || !n.messageId) | ||
return !0; | ||
const s = n, r = rt.find((h) => h.messageId === s.messageId); | ||
if (s.option.destination === L.SP) | ||
return !0; | ||
if (s.option.destination === L.CS) | ||
if (s.option.tabId) | ||
_t(s.messageId, s.data, s.option).then((h) => { | ||
P.debug && console.log("sendMsgByBG response(cs)", h), t({ data: h, success: !0 }); | ||
}); | ||
else | ||
return console.warn("没有 tabId,不给 content script 发送消息"), t({ msg: "not have tabId", success: !1 }), !1; | ||
else if (r && r.bgCallback) | ||
r.bgCallback(s.data, { | ||
option: s.option, | ||
messageId: s.messageId | ||
}).then((h) => { | ||
t({ data: h, success: !0 }); | ||
}).catch((h) => { | ||
console.error("bgCallback error", h), t({ data: void 0, msg: h.message, success: !1 }); | ||
}); | ||
else | ||
return console.warn("没有监听相关事件"), !0; | ||
return !0; | ||
} | ||
); | ||
} | ||
const it = []; | ||
function xt() { | ||
console.log("initCSMsgListener"), chrome.runtime.onMessage.addListener( | ||
(n, e, t) => { | ||
if (P.debug && console.log("cs", n), Object.prototype.toString.call(n) !== "[object Object]" || !n.messageId) | ||
return !0; | ||
const s = it.find((r) => r.messageId === n.messageId); | ||
if (!s || !s.csCallback) | ||
return console.warn("没有监听相关事件"), !0; | ||
if (s && s.csCallback) | ||
s.csCallback(n.data, { | ||
option: n.option, | ||
messageId: n.messageId | ||
}).then((r) => { | ||
t({ | ||
data: r, | ||
success: !0 | ||
}); | ||
}).catch((r) => { | ||
t({ | ||
data: void 0, | ||
success: !1, | ||
msg: r.message | ||
}); | ||
}); | ||
else | ||
return !1; | ||
return !0; | ||
} | ||
); | ||
} | ||
function et(n, e, t) { | ||
return new Promise((s) => { | ||
P.debug && console.log("cs sendMsgByCS", n, e, t), chrome.runtime.sendMessage({ messageId: n, data: e, option: t }, {}, (r) => { | ||
P.debug && console.log("cs sendMsgByCS response", n, r), s({ | ||
data: r == null ? void 0 : r.data, | ||
tabId: t.tabId, | ||
tabUrl: t.tabUrl, | ||
messageId: n, | ||
success: (r == null ? void 0 : r.success) || !1, | ||
msg: r == null ? void 0 : r.msg | ||
}); | ||
@@ -455,37 +553,86 @@ }); | ||
} | ||
function _t(r, t, e) { | ||
const n = ot.find((i) => i.messageId === r); | ||
return n ? n.csCallback = t : ot.push({ | ||
messageId: r, | ||
csCallback: t | ||
function pt(n, e, t) { | ||
const s = it.find((r) => r.messageId === n); | ||
return s ? s.csCallback = e : it.push({ | ||
messageId: n, | ||
csCallback: e | ||
}), !0; | ||
} | ||
const ct = []; | ||
function ht(r, t, e) { | ||
return new Promise((n) => { | ||
if (z.debug && console.log("sendMsgBySP", r, t, e), e.destination === x.CS && !e.tabId) | ||
return console.error("tabId is required"), n({ | ||
const nt = []; | ||
function Nt() { | ||
chrome.runtime.onMessage.addListener( | ||
(n, e, t) => { | ||
P.debug && console.log("sp receive", n, e); | ||
const s = nt.find((h) => h.messageId === n.messageId), r = n.option.destination; | ||
if (!r) | ||
throw new Error("destination is required"); | ||
if (s && s.spCallback) | ||
s.spCallback(n.data, { | ||
option: n.option, | ||
messageId: n.messageId | ||
}).then((h) => { | ||
t({ | ||
data: h, | ||
success: !0 | ||
}); | ||
}).catch((h) => { | ||
t({ | ||
data: void 0, | ||
success: !1, | ||
msg: h.message | ||
}); | ||
}); | ||
else if (r === L.SP) { | ||
const h = nt.find((l) => l.messageId === n.messageId); | ||
if (h && h.spCallback) | ||
h.spCallback(n.data, { | ||
option: n.option, | ||
messageId: n.messageId | ||
}).then((l) => { | ||
t({ | ||
data: l, | ||
success: !0 | ||
}); | ||
}).catch((l) => { | ||
t({ | ||
data: void 0, | ||
success: !1, | ||
msg: l.message | ||
}); | ||
}); | ||
else | ||
return; | ||
} else | ||
return; | ||
return !0; | ||
} | ||
); | ||
} | ||
function ht(n, e, t) { | ||
return new Promise((s) => { | ||
if (P.debug && console.log("sendMsgBySP", n, e, t), t.destination === L.CS && !t.tabId) | ||
return console.error("tabId is required"), s({ | ||
data: void 0, | ||
tabId: e.tabId, | ||
messageId: r, | ||
tabId: t.tabId, | ||
messageId: n, | ||
success: !1, | ||
msg: "tabId is required" | ||
}); | ||
chrome.runtime.sendMessage({ messageId: r, data: t, option: e }, {}, (i) => { | ||
if (z.debug && console.log("sp sendMsgBySP", i), e.destination === x.CS) { | ||
const T = i.data; | ||
return n({ | ||
data: T == null ? void 0 : T.data, | ||
tabId: e.tabId, | ||
messageId: r, | ||
success: (T == null ? void 0 : T.success) || !1, | ||
msg: T == null ? void 0 : T.msg | ||
chrome.runtime.sendMessage({ messageId: n, data: e, option: t }, {}, (r) => { | ||
if (P.debug && console.log("sp sendMsgBySP", r), t.destination === L.CS) { | ||
const h = r.data; | ||
return s({ | ||
data: h == null ? void 0 : h.data, | ||
tabId: t.tabId, | ||
messageId: n, | ||
success: (h == null ? void 0 : h.success) || !1, | ||
msg: h == null ? void 0 : h.msg | ||
}); | ||
} | ||
n({ | ||
data: i == null ? void 0 : i.data, | ||
tabId: e.tabId, | ||
messageId: r, | ||
success: (i == null ? void 0 : i.success) || !1, | ||
msg: i == null ? void 0 : i.msg | ||
s({ | ||
data: r == null ? void 0 : r.data, | ||
tabId: t.tabId, | ||
messageId: n, | ||
success: (r == null ? void 0 : r.success) || !1, | ||
msg: r == null ? void 0 : r.msg | ||
}); | ||
@@ -495,80 +642,80 @@ }); | ||
} | ||
function bt(r, t) { | ||
const e = ct.find((n) => n.messageId === r); | ||
e ? e.spCallback = t : ct.push({ | ||
messageId: r, | ||
spCallback: t | ||
function Et(n, e) { | ||
const t = nt.find((s) => s.messageId === n); | ||
t ? t.spCallback = e : nt.push({ | ||
messageId: n, | ||
spCallback: e | ||
}); | ||
} | ||
const ut = 5e3; | ||
class $t { | ||
constructor(t = {}) { | ||
class It { | ||
constructor(e = {}) { | ||
this.logCache = [], this.maxCacheSize = ut, this.options = { | ||
level: t.level || M.INFO, | ||
timestamp: t.timestamp ?? !0, | ||
prefix: t.prefix || "[Chrome Extension]", | ||
color: t.color ?? !0, | ||
isSyncToBG: t.isSyncToBG ?? !1, | ||
isSyncToSP: t.isSyncToSP ?? !1, | ||
isCS: t.isCS ?? !1 | ||
}, this.isShowInConsole = t.isShowInConsole ?? !1, this.maxCacheSize = t.maxCacheSize || ut; | ||
level: e.level || w.INFO, | ||
timestamp: e.timestamp ?? !0, | ||
prefix: e.prefix || "[Chrome Extension]", | ||
color: e.color ?? !0, | ||
isSyncToBG: e.isSyncToBG ?? !1, | ||
isSyncToSP: e.isSyncToSP ?? !1, | ||
isCS: e.isCS ?? !1 | ||
}, this.isShowInConsole = e.isShowInConsole ?? !1, this.maxCacheSize = e.maxCacheSize || ut; | ||
} | ||
getTimestamp() { | ||
return pt().format("YYYY-MM-DD HH:mm:ss"); | ||
return Ct().format("YYYY-MM-DD HH:mm:ss"); | ||
} | ||
formatMessage(t, e, ...n) { | ||
const i = []; | ||
return this.options.timestamp && i.push(`[${this.getTimestamp()}]`), i.push(this.options.prefix || "[Chrome Extension]"), i.push(`[${t.toUpperCase()}]`), i.push(e), i.join(" "); | ||
formatMessage(e, t, ...s) { | ||
const r = []; | ||
return this.options.timestamp && r.push(`[${this.getTimestamp()}]`), r.push(this.options.prefix || "[Chrome Extension]"), r.push(`[${e.toUpperCase()}]`), r.push(t), r.join(" "); | ||
} | ||
shouldLog(t) { | ||
const e = Object.values(M), n = e.indexOf(this.options.level || M.INFO); | ||
return e.indexOf(t) >= n; | ||
shouldLog(e) { | ||
const t = Object.values(w), s = t.indexOf(this.options.level || w.INFO); | ||
return t.indexOf(e) >= s; | ||
} | ||
addLog(t) { | ||
this.logCache.unshift(t), this.logCache.length > this.maxCacheSize && this.logCache.pop(); | ||
addLog(e) { | ||
this.logCache.unshift(e), this.logCache.length > this.maxCacheSize && this.logCache.pop(); | ||
} | ||
log(t) { | ||
this.log(t); | ||
log(e) { | ||
this.log(e); | ||
} | ||
syncToBG(t) { | ||
this.options.isCS && this.options.isSyncToBG ? et(L.CS2BG_LOG, t, { destination: x.BG }) : this.options.isSP && this.options.isSyncToBG && ht(L.SP2BG_LOG, t, { destination: x.BG }); | ||
syncToBG(e) { | ||
this.options.isCS && this.options.isSyncToBG ? et(v.CS2BG_LOG, e, { destination: L.BG }) : this.options.isSP && this.options.isSyncToBG && ht(v.SP2BG_LOG, e, { destination: L.BG }); | ||
} | ||
syncToSP(t) { | ||
this.options.isCS && this.options.isSyncToSP && et(L.CS2SP_LOG, t, { destination: x.SP }); | ||
syncToSP(e) { | ||
this.options.isCS && this.options.isSyncToSP && et(v.CS2SP_LOG, e, { destination: L.SP }); | ||
} | ||
addToCache(t, e, n) { | ||
const i = { | ||
addToCache(e, t, s) { | ||
const r = { | ||
timestamp: this.getTimestamp(), | ||
level: t, | ||
message: e, | ||
args: n | ||
level: e, | ||
message: t, | ||
args: s | ||
}; | ||
this.addLog(i), this.syncToBG(i), this.syncToSP(i); | ||
this.addLog(r), this.syncToBG(r), this.syncToSP(r); | ||
} | ||
debug(t, ...e) { | ||
if (this.shouldLog(M.DEBUG)) { | ||
const n = this.formatMessage(M.DEBUG, t, ...e); | ||
this.isShowInConsole && console.debug(n, ...e), this.addToCache(M.DEBUG, t, e); | ||
debug(e, ...t) { | ||
if (this.shouldLog(w.DEBUG)) { | ||
const s = this.formatMessage(w.DEBUG, e, ...t); | ||
this.isShowInConsole && console.debug(s, ...t), this.addToCache(w.DEBUG, e, t); | ||
} | ||
} | ||
info(t, ...e) { | ||
if (this.shouldLog(M.INFO)) { | ||
const n = this.formatMessage(M.INFO, t, ...e); | ||
this.isShowInConsole && console.info(n, ...e), this.addToCache(M.INFO, t, e); | ||
info(e, ...t) { | ||
if (this.shouldLog(w.INFO)) { | ||
const s = this.formatMessage(w.INFO, e, ...t); | ||
this.isShowInConsole && console.info(s, ...t), this.addToCache(w.INFO, e, t); | ||
} | ||
} | ||
warn(t, ...e) { | ||
if (this.shouldLog(M.WARN)) { | ||
const n = this.formatMessage(M.WARN, t, ...e); | ||
this.isShowInConsole && console.warn(n, ...e), this.addToCache(M.WARN, t, e); | ||
warn(e, ...t) { | ||
if (this.shouldLog(w.WARN)) { | ||
const s = this.formatMessage(w.WARN, e, ...t); | ||
this.isShowInConsole && console.warn(s, ...t), this.addToCache(w.WARN, e, t); | ||
} | ||
} | ||
error(t, ...e) { | ||
if (this.shouldLog(M.ERROR)) { | ||
const n = this.formatMessage(M.ERROR, t, ...e); | ||
this.isShowInConsole && console.error(n, ...e), this.addToCache(M.ERROR, t, e); | ||
error(e, ...t) { | ||
if (this.shouldLog(w.ERROR)) { | ||
const s = this.formatMessage(w.ERROR, e, ...t); | ||
this.isShowInConsole && console.error(s, ...t), this.addToCache(w.ERROR, e, t); | ||
} | ||
} | ||
setOptions(t) { | ||
this.options = { ...this.options, ...t }; | ||
setOptions(e) { | ||
this.options = { ...this.options, ...e }; | ||
} | ||
@@ -580,4 +727,4 @@ // 获取所有缓存的日志 | ||
// 获取指定级别的日志 | ||
getLogsByLevel(t) { | ||
return this.logCache.filter((e) => e.level === t); | ||
getLogsByLevel(e) { | ||
return this.logCache.filter((t) => t.level === e); | ||
} | ||
@@ -593,20 +740,20 @@ // 清空日志缓存 | ||
} | ||
function Et(r = 1e3) { | ||
return new Promise((t) => setTimeout(t, r)); | ||
function $t(n = 1e3) { | ||
return new Promise((e) => setTimeout(e, n)); | ||
} | ||
async function Rt(r, t = 10, e = 1e3) { | ||
let n = 0, i = !1; | ||
for (; n < t && (n > 0 && await Et(e), i = await r(n), !i); ) | ||
n++; | ||
return i; | ||
async function Mt(n, e = 10, t = 1e3) { | ||
let s = 0, r = !1; | ||
for (; s < e && (s > 0 && await $t(t), r = await n(s), !r); ) | ||
s++; | ||
return r; | ||
} | ||
function wt(r) { | ||
return r != null; | ||
function wt(n) { | ||
return n != null; | ||
} | ||
class Mt { | ||
class Rt { | ||
constructor() { | ||
this.stack = []; | ||
} | ||
push(t) { | ||
this.stack.push(t); | ||
push(e) { | ||
this.stack.push(e); | ||
} | ||
@@ -620,4 +767,4 @@ pop() { | ||
peekAdd() { | ||
const t = this.stack[this.stack.length - 1]; | ||
t !== void 0 && (this.stack[this.stack.length - 1] = t + 1); | ||
const e = this.stack[this.stack.length - 1]; | ||
e !== void 0 && (this.stack[this.stack.length - 1] = e + 1); | ||
} | ||
@@ -628,47 +775,47 @@ isEmpty() { | ||
} | ||
function It(r, t) { | ||
let e; | ||
for (const n of r) { | ||
if (n.name === t) { | ||
e = n; | ||
function Bt(n, e) { | ||
let t; | ||
for (const s of n) { | ||
if (s.name === e) { | ||
t = s; | ||
break; | ||
} | ||
if (n.children && (e = It(n.children, t), e)) | ||
if (s.children && (t = Bt(s.children, e), t)) | ||
break; | ||
} | ||
return e; | ||
return t; | ||
} | ||
function k(r) { | ||
function N(n) { | ||
try { | ||
return JSON.stringify(r); | ||
} catch (t) { | ||
return console.log("parse error", t), r; | ||
return JSON.stringify(n); | ||
} catch (e) { | ||
return console.log("parse error", e), n; | ||
} | ||
} | ||
function xt(r) { | ||
function Ut(n) { | ||
try { | ||
return JSON.parse(r); | ||
} catch (t) { | ||
return console.log("parse error", t), r; | ||
return JSON.parse(n); | ||
} catch (e) { | ||
return console.log("parse error", e), n; | ||
} | ||
} | ||
function Gt(r = 9999999999, t = 1e9) { | ||
return Math.floor(Math.random() * (r - t + 1) + t); | ||
function Gt(n = 9999999999, e = 1e9) { | ||
return Math.floor(Math.random() * (n - e + 1) + e); | ||
} | ||
function Ot(r, t) { | ||
return new Promise((e) => { | ||
function At(n, e) { | ||
return new Promise((t) => { | ||
chrome.scripting.registerContentScripts([ | ||
{ | ||
id: "intercept-request", | ||
js: [r], | ||
js: [n], | ||
world: "MAIN", | ||
persistAcrossSessions: !1, | ||
matches: t | ||
matches: e | ||
} | ||
], () => { | ||
e(!0); | ||
t(!0); | ||
}); | ||
}); | ||
} | ||
const D = new $t({ | ||
const O = new It({ | ||
isCS: !0, | ||
@@ -678,3 +825,3 @@ isSP: !0, | ||
isSyncToSP: !0, | ||
level: M.DEBUG | ||
level: w.DEBUG | ||
}); | ||
@@ -691,204 +838,213 @@ function lt() { | ||
} | ||
class ft { | ||
constructor(t, e, n = {}) { | ||
var T, h; | ||
this.name = "", this.tabId = 0, this.children = [], this.indexPath = [], this.level = 0, this.nextTaskPath = [], this.hasChildren = !1, this.isRoot = !1, this.isCurrentLast = !1, this.isLoopItem = !1, this.parentLoopData = [], this.name = t.name, this.configure = t, this.indexPath = e, this.level = e.length; | ||
const i = e.length - 1; | ||
this.nextTaskPath = e.map((b, l) => l === i ? e[i] + 1 : b), this.hasChildren = !!((T = t.children) != null && T.length), this.isRoot = !!n.isRoot, this.isCurrentLast = !!n.isCurrentLast, this.isLoopItem = !!((h = n.parentLoopData) != null && h.length), this.parentLoopData = n.parentLoopData || []; | ||
class dt { | ||
constructor(e, t, s = {}) { | ||
var h, l; | ||
this.name = "", this.tabId = 0, this.children = [], this.indexPath = [], this.level = 0, this.nextTaskPath = [], this.hasChildren = !1, this.isRoot = !1, this.isCurrentLast = !1, this.isLoopItem = !1, this.parentLoopData = [], this.name = e.name, this.configure = e, this.indexPath = t, this.level = t.length; | ||
const r = t.length - 1; | ||
this.nextTaskPath = t.map((p, d) => d === r ? t[r] + 1 : p), this.hasChildren = !!((h = e.children) != null && h.length), this.isRoot = !!s.isRoot, this.isCurrentLast = !!s.isCurrentLast, this.isLoopItem = !!((l = s.parentLoopData) != null && l.length), this.parentLoopData = s.parentLoopData || []; | ||
} | ||
setTabId(t) { | ||
this.tabId = t; | ||
setTabId(e) { | ||
this.tabId = e; | ||
} | ||
appendChildren(t) { | ||
this.children = t, this.hasChildren = t.length > 0; | ||
appendChildren(e) { | ||
this.children = e, this.hasChildren = e.length > 0; | ||
} | ||
async run(t, e) { | ||
const n = this.configure; | ||
e.logItem = { | ||
name: n.name, | ||
async run(e, t) { | ||
const s = this.configure; | ||
t.logItem = { | ||
name: s.name, | ||
success: !1 | ||
}; | ||
const i = { isFirstLevel: !0, name: this.name }; | ||
t.isRetry && t.currentRetryNumber > 0 && (i.retryNumber = t.currentRetryNumber), wt(e.currentLoopData) && (i.currentLoopData = e.currentLoopData, i.currentLoopIndex = e.currentLoopIndex); | ||
const T = n.spBeforeFn ? await n.spBeforeFn(i) : lt(); | ||
if (e.logItem.spBeforeFn = T, !T || !T.next) | ||
const r = { isFirstLevel: !0, name: this.name }; | ||
e.isRetry && e.currentRetryNumber > 0 && (r.retryNumber = e.currentRetryNumber), wt(t.currentLoopData) && (r.currentLoopData = t.currentLoopData, r.currentLoopIndex = t.currentLoopIndex); | ||
const h = s.spBeforeFn ? await s.spBeforeFn(r) : lt(); | ||
if (t.logItem.spBeforeFn = h, !h || !h.next) | ||
return !1; | ||
const h = vt(); | ||
if (n.csFn && await Rt(async (l) => { | ||
const c = await ht(L.SP2CS_EXECUTE_TASK, { | ||
...i, | ||
spBeforeFnResult: T, | ||
csRetryNumber: l, | ||
const l = vt(); | ||
if (s.csFn && await Mt(async (d) => { | ||
const c = await ht(v.SP2CS_EXECUTE_TASK, { | ||
...r, | ||
spBeforeFnResult: h, | ||
csRetryNumber: d, | ||
tabId: this.tabId | ||
}, { | ||
destination: x.CS, | ||
destination: L.CS, | ||
tabId: this.tabId | ||
}); | ||
return console.log("msgResult", c), h.tabId = c.tabId, h.tabUrl = c.tabUrl, h.data = c.data, h.next = c.success, h.next; | ||
}, (n.csRetryNumber || 0) + 1, n.csRetryInterval || 1e3), e.logItem.csFn = h, !h || !h.next && !n.skipCsCallbackFail) | ||
return console.log("msgResult", c), l.tabId = c.tabId, l.tabUrl = c.tabUrl, l.data = c.data, l.next = c.success, l.next; | ||
}, (s.csRetryNumber || 0) + 1, s.csRetryInterval || 1e3), t.logItem.csFn = l, !l || !l.next && !s.skipCsCallbackFail) | ||
return !1; | ||
const b = n.spAfterFn ? await n.spAfterFn({ | ||
...i, | ||
csFnResult: h | ||
const p = s.spAfterFn ? await s.spAfterFn({ | ||
...r, | ||
csFnResult: l | ||
}) : lt(); | ||
return e.logItem.spAfterFn = b, !b || !b.next ? !1 : (e.logItem.success = !0, !0); | ||
return t.logItem.spAfterFn = p, !p || !p.next ? !1 : (t.logItem.success = !0, !0); | ||
} | ||
} | ||
function dt(r, t = [], e, n) { | ||
return r.map((T, h) => { | ||
function ft(n, e = [], t, s) { | ||
return n.map((h, l) => { | ||
var c; | ||
const b = h === r.length - 1, l = new ft(T, [...t, h], { | ||
isCurrentLast: b, | ||
parentLoopData: ((c = n == null ? void 0 : n.configure) == null ? void 0 : c.loopData) || [] | ||
const p = l === n.length - 1, d = new dt(h, [...e, l], { | ||
isCurrentLast: p, | ||
parentLoopData: ((c = s == null ? void 0 : s.configure) == null ? void 0 : c.loopData) || [] | ||
}); | ||
return e[T.name] = l.indexPath, T.children && (l.children = dt(T.children, [...t, h], e, l)), l; | ||
return t[h.name] = d.indexPath, h.children && (d.children = ft(h.children, [...e, l], t, d)), d; | ||
}); | ||
} | ||
function Lt(r) { | ||
const t = {}, e = new ft({ name: "root", children: [] }, [], { isRoot: !0 }); | ||
return e.appendChildren(dt(r, [], t)), { rootTask: e, nameMap: t }; | ||
function Lt(n) { | ||
const e = {}, t = new dt({ name: "root", children: [] }, [], { isRoot: !0 }); | ||
return t.appendChildren(ft(n, [], e)), { rootTask: t, nameMap: e }; | ||
} | ||
function X(r, t) { | ||
if (t.length) | ||
function z(n, e) { | ||
if (e.length) | ||
try { | ||
let e = r; | ||
const n = [...t]; | ||
for (let i = 0; i < n.length; i++) | ||
e = e.children[n[i]]; | ||
return e; | ||
} catch (e) { | ||
console.log(e); | ||
let t = n; | ||
const s = [...e]; | ||
for (let r = 0; r < s.length; r++) | ||
t = t.children[s[r]]; | ||
return t; | ||
} catch (t) { | ||
console.log(t); | ||
return; | ||
} | ||
} | ||
function gt(r, t) { | ||
const e = X(r, t); | ||
if (!e) | ||
function gt(n, e) { | ||
const t = z(n, e); | ||
if (!t) | ||
return; | ||
const n = X(r, e.nextTaskPath); | ||
return n || gt(r, e.indexPath.slice(0, -1)); | ||
const s = z(n, t.nextTaskPath); | ||
return s || gt(n, t.indexPath.slice(0, -1)); | ||
} | ||
const Bt = 1e3 * 1 * 60; | ||
class kt { | ||
constructor(t, e) { | ||
this.configures = t, this.params = e || { nextTime: Bt }; | ||
const kt = 1e3 * 1 * 60; | ||
class Ft { | ||
constructor(e, t) { | ||
this.configures = e, this.params = t || { nextTime: kt }; | ||
} | ||
getActuatorCache(t) { | ||
return t.reduce((e, n) => (e[n.name] = { | ||
name: n.name, | ||
retryNumber: n.retryNumber || 0, | ||
getActuatorCache(e) { | ||
return e.reduce((t, s) => (t[s.name] = { | ||
name: s.name, | ||
retryNumber: s.retryNumber || 0, | ||
currentRetryNumber: 0, | ||
isRetry: !!n.retryTarget | ||
}, n.children && Object.assign(e, this.getActuatorCache(n.children)), e), {}); | ||
isRetry: !!s.retryTarget | ||
}, s.children && Object.assign(t, this.getActuatorCache(s.children)), t), {}); | ||
} | ||
getRetryTargetIndex(t) { | ||
return this.configures.findIndex((e) => e.name === t); | ||
getRetryTargetIndex(e) { | ||
return this.configures.findIndex((t) => t.name === e); | ||
} | ||
checkIsSameName(t, e = {}) { | ||
return t.some((n) => e[n.name] ? !0 : (e[n.name] = !0, n.children ? this.checkIsSameName(n.children, e) : !1)); | ||
checkIsSameName(e, t = {}) { | ||
return e.some((s) => t[s.name] ? !0 : (t[s.name] = !0, s.children ? this.checkIsSameName(s.children, t) : !1)); | ||
} | ||
findConfigureByName(t) { | ||
let e; | ||
return this.configures.some((n) => n.name === t ? (e = n, !0) : n.children ? this.findConfigureByName(t) : !1), e; | ||
findConfigureByName(e) { | ||
let t; | ||
return this.configures.some((s) => s.name === e ? (t = s, !0) : s.children ? this.findConfigureByName(e) : !1), t; | ||
} | ||
async run() { | ||
var g, $, p, E; | ||
var m, E, C, I; | ||
if (this.checkIsSameName(this.configures)) | ||
throw console.log("error"), new Error("name 不能重复"); | ||
const t = [], e = { | ||
const e = [], t = { | ||
logItem: void 0 | ||
}, n = this.getActuatorCache(this.configures), { rootTask: i, nameMap: T } = Lt(this.configures); | ||
let h = i, b = !1, l = 1, c = !1; | ||
const d = new Mt(); | ||
for (; h; ) { | ||
if (h.isRoot) { | ||
h = h.children[0], l = h.level; | ||
}, s = this.getActuatorCache(this.configures), { rootTask: r, nameMap: h } = Lt(this.configures); | ||
let l = r, p = !1, d = 1, c = !1; | ||
const g = new Rt(); | ||
for (; l; ) { | ||
if (l.isRoot) { | ||
l = l.children[0], d = l.level; | ||
continue; | ||
} | ||
const P = n[h.name], N = await (($ = (g = this.params).getTabId) == null ? void 0 : $.call(g, h, P, e)); | ||
N && h.setTabId(N); | ||
const Q = await h.run(P, e); | ||
if (P.isRetry && !Q && (P.currentRetryNumber++, P.currentRetryNumber <= P.retryNumber)) { | ||
const j = X(i, T[h.configure.retryTarget]); | ||
if (!j) | ||
throw new Error(`retryTargetIndex not found, ${h.configure.retryTarget}`); | ||
h = j; | ||
const D = s[l.name], U = await ((E = (m = this.params).getTabId) == null ? void 0 : E.call(m, l, D, t)); | ||
U && l.setTabId(U); | ||
const Q = await l.run(D, t); | ||
if (D.isRetry && !Q && (D.currentRetryNumber++, D.currentRetryNumber <= D.retryNumber)) { | ||
const q = z(r, h[l.configure.retryTarget]); | ||
if (!q) | ||
throw new Error(`retryTargetIndex not found, ${l.configure.retryTarget}`); | ||
l = q; | ||
continue; | ||
} | ||
if (e.logItem && t.push(e.logItem), !Q) | ||
if (t.logItem && e.push(t.logItem), !Q) | ||
break; | ||
let G; | ||
if (h.hasChildren ? (b = !0, G = h.children[0]) : G = X(i, h.nextTaskPath), !G) | ||
if (c && (d.peek() || 0) < h.parentLoopData.length - 1) | ||
d.peekAdd(), G = X(i, [...h.indexPath.slice(0, -1), 0]); | ||
else if (b && h.isCurrentLast) { | ||
if (G = gt(i, h.indexPath.slice(0, -1)), !G) | ||
let B; | ||
if (l.hasChildren ? (p = !0, B = l.children[0]) : B = z(r, l.nextTaskPath), !B) | ||
if (c && (g.peek() || 0) < l.parentLoopData.length - 1) | ||
g.peekAdd(), B = z(r, [...l.indexPath.slice(0, -1), 0]); | ||
else if (p && l.isCurrentLast) { | ||
if (B = gt(r, l.indexPath.slice(0, -1)), !B) | ||
break; | ||
b = G.level !== 1; | ||
p = B.level !== 1; | ||
} else | ||
break; | ||
c = G.isLoopItem, l < G.level ? c && d.push(0) : l > G.level && c && d.pop(), c && (e.currentLoopData = G.parentLoopData[d.peek()], e.currentLoopIndex = d.peek()), l = G.level, h = G; | ||
c = B.isLoopItem, d < B.level ? c && g.push(0) : d > B.level && c && g.pop(), c && (t.currentLoopData = B.parentLoopData[g.peek()], t.currentLoopIndex = g.peek()), d = B.level, l = B; | ||
} | ||
return (E = (p = this.params).callback) == null || E.call(p, t), console.log("end"), t; | ||
return (I = (C = this.params).callback) == null || I.call(C, e), console.log("end"), e; | ||
} | ||
} | ||
function Nt() { | ||
D.info("initService"), Z(L.CS2BG_LOG, async (r) => { | ||
D.log(r); | ||
}), Z(L.SP2BG_LOG, async (r) => { | ||
D.log(r); | ||
}), Z(L.SP2BG_GET_CURRENT_TAB, async (r, t) => { | ||
D.info("bg SP2BG_GET_CURRENT_TAB: ", k(r), k(t)); | ||
const e = await chrome.tabs.query({ active: !0, currentWindow: !0 }); | ||
return D.info("bg SP2BG_GET_CURRENT_TAB RESULT: ", k(e)), e[0]; | ||
}), Z(L.CS2BG_GET_CURRENT_TAB, async (r, t) => { | ||
D.info("bg CS2BG_GET_CURRENT_TAB: ", k(r), k(t)); | ||
const e = await chrome.tabs.query({ active: !0, currentWindow: !0 }); | ||
return D.info("bg CS2BG_GET_CURRENT_TAB RESULT: ", k(e)), e[0]; | ||
function jt() { | ||
O.info("initService"), Z(v.CS2BG_LOG, async (n) => { | ||
O.log(n); | ||
}), Z(v.SP2BG_LOG, async (n) => { | ||
O.log(n); | ||
}), Z(v.SP2BG_GET_CURRENT_TAB, async (n, e) => { | ||
O.info("bg SP2BG_GET_CURRENT_TAB: ", N(n), N(e)); | ||
const t = await chrome.tabs.query({ active: !0, currentWindow: !0 }); | ||
return O.info("bg SP2BG_GET_CURRENT_TAB RESULT: ", N(t)), t[0]; | ||
}), Z(v.CS2BG_GET_CURRENT_TAB, async (n, e) => { | ||
O.info("bg CS2BG_GET_CURRENT_TAB: ", N(n), N(e)); | ||
const t = await chrome.tabs.query({ active: !0, currentWindow: !0 }); | ||
return O.info("bg CS2BG_GET_CURRENT_TAB RESULT: ", N(t)), t[0]; | ||
}); | ||
} | ||
function Ut() { | ||
D.info("initSidePanel"), bt(L.CS2SP_LOG, async (r) => { | ||
D.log(r); | ||
function qt() { | ||
O.info("initSidePanel"), Et(v.CS2SP_LOG, async (n) => { | ||
O.log(n); | ||
}); | ||
} | ||
function At(r) { | ||
D.info("initContentScript"), window.addEventListener("message", (t) => { | ||
if (t.data && t.data.type === L.GET_CONTENT_SCRIPT_REQUEST) { | ||
const e = k(t.data.data.response), n = { | ||
url: t.data.data.url, | ||
response: e, | ||
requestType: t.data.data.requestType, | ||
function Ht(n) { | ||
O.info("initContentScript"), window.addEventListener("message", (e) => { | ||
if (e.data && e.data.type === v.GET_CONTENT_SCRIPT_REQUEST) { | ||
const t = N(e.data.data.response), s = { | ||
url: e.data.data.url, | ||
response: t, | ||
requestType: e.data.data.requestType, | ||
id: Gt() | ||
}; | ||
et(L.CS2SP_GET_REQUEST, n, { destination: x.SP }), et(L.CS2BG_GET_REQUEST, n, { destination: x.BG }); | ||
et(v.CS2SP_GET_REQUEST, s, { destination: L.SP }), et(v.CS2BG_GET_REQUEST, s, { destination: L.BG }); | ||
} | ||
}, !1), r && _t(L.SP2CS_EXECUTE_TASK, async (t) => { | ||
var n; | ||
D.info("SP2CS_EXECUTE_TASK: ", k(t)); | ||
const e = (n = r.find((i) => i.name === t.name)) == null ? void 0 : n.csFn; | ||
return e ? await e(t) : { next: !0 }; | ||
}, !1), n && pt(v.SP2CS_EXECUTE_TASK, async (e) => { | ||
var s; | ||
O.info("SP2CS_EXECUTE_TASK: ", N(e)); | ||
const t = (s = n.find((r) => r.name === e.name)) == null ? void 0 : s.csFn; | ||
return t ? await t(e) : { next: !0 }; | ||
}); | ||
} | ||
export { | ||
kt as CetActuator, | ||
x as CetDestination, | ||
M as CetLogLevel, | ||
$t as CetLogger, | ||
L as EVENTS, | ||
Mt as SimpleStack, | ||
Et as asyncSetTimeout, | ||
z as configures, | ||
xt as deserializeJSON, | ||
It as findDeepTargetByName, | ||
Ft as CetActuator, | ||
L as CetDestination, | ||
w as CetLogLevel, | ||
It as CetLogger, | ||
v as EVENTS, | ||
Rt as SimpleStack, | ||
$t as asyncSetTimeout, | ||
P as configures, | ||
Ut as deserializeJSON, | ||
Bt as findDeepTargetByName, | ||
Gt as generateTenDigitRandom, | ||
At as initContentScript, | ||
Dt as initInterceptRequest, | ||
Nt as initService, | ||
Ut as initSidePanel, | ||
Ot as injectInterceptRequest, | ||
Dt as initBGMsgListener, | ||
xt as initCSMsgListener, | ||
Ht as initContentScript, | ||
Pt as initInterceptRequest, | ||
Nt as initSPMsgListener, | ||
jt as initService, | ||
qt as initSidePanel, | ||
At as injectInterceptRequest, | ||
wt as isExist, | ||
Rt as loopCheck, | ||
k as serializeJSON, | ||
Pt as toggleDebug | ||
Mt as loopCheck, | ||
Z as onMsgInBG, | ||
pt as onMsgInCS, | ||
Et as onMsgInSP, | ||
_t as sendMsgByBG, | ||
et as sendMsgByCS, | ||
ht as sendMsgBySP, | ||
N as serializeJSON, | ||
Ot as toggleDebug | ||
}; |
export * from './components/intercept-request'; | ||
export * from './components/logger'; | ||
export * from './constants'; | ||
export * from './message'; | ||
export * from './types'; | ||
export * from './utils'; | ||
export * from './workflow'; |
{ | ||
"name": "chrome-extension-tools", | ||
"type": "module", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"packageManager": "pnpm@9.15.3", | ||
@@ -6,0 +6,0 @@ "author": "rni-l", |
Sorry, the diff of this file is not supported yet
82987
9.73%1452
13.08%