domquery-com 1.0.0
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/LICENSE +22 -0
- package/README.ko.md +273 -0
- package/README.md +272 -0
- package/domquery.js +6290 -0
- package/domquery.min.js +361 -0
- package/package.json +53 -0
- package/src/Kcolor.js +909 -0
- package/src/ajax.js +1220 -0
- package/src/alert.js +3516 -0
- package/src/animate.js +1775 -0
- package/src/lazyLoadImages.js +202 -0
- package/src/pulling.js +473 -0
- package/src/select.js +3154 -0
- package/src_min/Kcolor.min.js +45 -0
- package/src_min/ajax.min.js +61 -0
- package/src_min/alert.min.js +240 -0
- package/src_min/animate.min.js +118 -0
- package/src_min/lazyLoadImages.min.js +13 -0
- package/src_min/pulling.min.js +23 -0
- package/src_min/select.min.js +186 -0
package/src/ajax.js
ADDED
|
@@ -0,0 +1,1220 @@
|
|
|
1
|
+
const AJAX_CONFIG = {
|
|
2
|
+
VERSION: "5.0",
|
|
3
|
+
DEFAULT_TIMEOUT: 3E4,
|
|
4
|
+
TEST_URL_PATTERN: "http://host",
|
|
5
|
+
CALLBACK_PREFIX: "ajax_callback_",
|
|
6
|
+
REQUEST_PREFIX: "req_",
|
|
7
|
+
JSONP_CALLBACK_PREFIX: "jsonp_callback_",
|
|
8
|
+
SUCCESS_CALLBACK_PREFIX: "ajax_success_",
|
|
9
|
+
ERROR_CALLBACK_PREFIX: "ajax_error_",
|
|
10
|
+
HTTP_RESPONSE_PREFIX: "httpResponse_",
|
|
11
|
+
HTTP_ERROR_PREFIX: "httpError_",
|
|
12
|
+
MAX_CALLBACK_RETRY: 3,
|
|
13
|
+
BRIDGE_FALLBACK_DELAY: 100,
|
|
14
|
+
DEFAULT_CONTENT_TYPE: "application/x-www-form-urlencoded; charset=UTF-8",
|
|
15
|
+
FILE_URL_HANDLING: {
|
|
16
|
+
FORCE_WEBVIEW_BRIDGE: !0,
|
|
17
|
+
DISABLE_FALLBACK: !0,
|
|
18
|
+
IMMEDIATE_BRIDGE_CHECK: !0,
|
|
19
|
+
ENHANCED_TIMEOUT: 6E4,
|
|
20
|
+
LOG_ALL_STEPS: !0
|
|
21
|
+
},
|
|
22
|
+
DETECTION: {
|
|
23
|
+
URL_SCHEME_PRIORITY: 1,
|
|
24
|
+
BRIDGE_EXISTENCE_PRIORITY: 2,
|
|
25
|
+
USER_AGENT_PRIORITY: 3,
|
|
26
|
+
URL_SCHEMES: {
|
|
27
|
+
"file://": "webview_bridge",
|
|
28
|
+
"content://": "webview_bridge",
|
|
29
|
+
"android_asset://": "webview_bridge",
|
|
30
|
+
"http://": "auto",
|
|
31
|
+
"https://": "auto"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
BRIDGE: {
|
|
35
|
+
ANDROID_BRIDGES: [{
|
|
36
|
+
name: "AndroidBridge",
|
|
37
|
+
method: "httpRequest",
|
|
38
|
+
priority: 1
|
|
39
|
+
}, {
|
|
40
|
+
name: "Android",
|
|
41
|
+
method: "httpRequest",
|
|
42
|
+
priority: 2
|
|
43
|
+
}],
|
|
44
|
+
IOS_BRIDGE: {
|
|
45
|
+
name: "webkit.messageHandlers.httpRequest",
|
|
46
|
+
priority: 1
|
|
47
|
+
},
|
|
48
|
+
FILE_URL_CONFIG: {
|
|
49
|
+
timeout: 6E4,
|
|
50
|
+
retries: 2,
|
|
51
|
+
immediate_execution: !0
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
DEBUG: {
|
|
55
|
+
ENABLED: !1,
|
|
56
|
+
FILE_URL_VERBOSE: !0,
|
|
57
|
+
BRIDGE_CALL_TRACE: !0,
|
|
58
|
+
STEP_BY_STEP_LOG: !0,
|
|
59
|
+
CONSOLE_PREFIX: "[AJAX5-FILE]"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
customBridges = new Map,
|
|
63
|
+
bridgePriority = {
|
|
64
|
+
custom: 1,
|
|
65
|
+
android: 2,
|
|
66
|
+
ios: 3,
|
|
67
|
+
web: 4
|
|
68
|
+
},
|
|
69
|
+
domquery_SCRIPT_STORAGE_PREFIX = "ajax_script_",
|
|
70
|
+
domquery_SCRIPT_STORAGE_EXPIRY = 864E5,
|
|
71
|
+
domquery_hashString = a => {
|
|
72
|
+
let b = 0;
|
|
73
|
+
if (!a) return "0";
|
|
74
|
+
for (let d = 0; d < a.length; d++) {
|
|
75
|
+
const c = a.charCodeAt(d);
|
|
76
|
+
b = (b << 5) - b + c;
|
|
77
|
+
b &= b
|
|
78
|
+
}
|
|
79
|
+
return Math.abs(b).toString(36)
|
|
80
|
+
},
|
|
81
|
+
domquery_scriptRegistry = new Map,
|
|
82
|
+
domquery_SCRIPT_STATES = {
|
|
83
|
+
STORED: "stored",
|
|
84
|
+
LOADED: "loaded",
|
|
85
|
+
EXECUTED: "executed",
|
|
86
|
+
ERROR: "error",
|
|
87
|
+
REMOVED: "removed"
|
|
88
|
+
},
|
|
89
|
+
domquery_isScriptAlreadyLoaded = (a, b) => {
|
|
90
|
+
for (const [, d] of domquery_scriptRegistry.entries())
|
|
91
|
+
if (d.state === domquery_SCRIPT_STATES.EXECUTED && (a && d.src === a || !a && b && d.content === b)) return !0;
|
|
92
|
+
return !1
|
|
93
|
+
},
|
|
94
|
+
domquery_extractAndStoreScripts = (a, b) => {
|
|
95
|
+
if (!a || "string" !== typeof a) return a;
|
|
96
|
+
if ("undefined" === typeof DOMParser) return {
|
|
97
|
+
cleanHtml: a,
|
|
98
|
+
storageKeys: [],
|
|
99
|
+
skippedCount: 0
|
|
100
|
+
};
|
|
101
|
+
a = (new DOMParser).parseFromString(a, "text/html");
|
|
102
|
+
const d = [];
|
|
103
|
+
let c =
|
|
104
|
+
0;
|
|
105
|
+
a.querySelectorAll("script").forEach((e, g) => {
|
|
106
|
+
var h = e.src || null;
|
|
107
|
+
const f = e.textContent || null;
|
|
108
|
+
if (domquery_isScriptAlreadyLoaded(h, f)) c++;
|
|
109
|
+
else {
|
|
110
|
+
var l = h ? `${domquery_SCRIPT_STORAGE_PREFIX}src_${domquery_hashString(h)}` : f ? `${domquery_SCRIPT_STORAGE_PREFIX}content_${domquery_hashString(f)}` : `${domquery_SCRIPT_STORAGE_PREFIX}${g}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;
|
|
111
|
+
h = {
|
|
112
|
+
src: h,
|
|
113
|
+
content: f,
|
|
114
|
+
type: e.type || "text/javascript",
|
|
115
|
+
async: e.async || !1,
|
|
116
|
+
defer: e.defer || !1,
|
|
117
|
+
timestamp: Date.now(),
|
|
118
|
+
originalUrl: b ||
|
|
119
|
+
null
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
if ("undefined" !== typeof localStorage) {
|
|
123
|
+
const k = localStorage.getItem(l);
|
|
124
|
+
if (k) try {
|
|
125
|
+
const q = JSON.parse(k);
|
|
126
|
+
q.timestamp = Date.now();
|
|
127
|
+
localStorage.setItem(l, JSON.stringify(q))
|
|
128
|
+
} catch (q) {
|
|
129
|
+
localStorage.setItem(l, JSON.stringify(h))
|
|
130
|
+
} else localStorage.setItem(l, JSON.stringify(h))
|
|
131
|
+
}
|
|
132
|
+
} catch (k) {}
|
|
133
|
+
d.push(l);
|
|
134
|
+
domquery_scriptRegistry.set(l, {
|
|
135
|
+
...h,
|
|
136
|
+
state: domquery_SCRIPT_STATES.STORED,
|
|
137
|
+
registeredAt: Date.now(),
|
|
138
|
+
index: g
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
e.remove()
|
|
142
|
+
});
|
|
143
|
+
return {
|
|
144
|
+
cleanHtml: a.documentElement.outerHTML,
|
|
145
|
+
storageKeys: d,
|
|
146
|
+
skippedCount: c
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
domquery_processScriptWithFunctionCall =
|
|
150
|
+
(a, b) => {
|
|
151
|
+
if (!a || "string" !== typeof a || !b) return {
|
|
152
|
+
processedContent: a,
|
|
153
|
+
extractedTexts: []
|
|
154
|
+
};
|
|
155
|
+
const d = new Map;
|
|
156
|
+
var c = a.split("\n");
|
|
157
|
+
const e = [...c];
|
|
158
|
+
let g = !1,
|
|
159
|
+
h = 0;
|
|
160
|
+
c.forEach((f, l) => {
|
|
161
|
+
if (f.includes("// domqGLG") && (!f.match(/\/\/\s*domqGLG_(\w+)/) || f.match(/\/\/\s*domqGLG\s+(\[[^\]]+\])/))) {
|
|
162
|
+
var k = null,
|
|
163
|
+
q = [],
|
|
164
|
+
t = f.match(/\/\/\s*domqGLG(?:_\w+)?\s+(\[[^\]]+\])/);
|
|
165
|
+
if (t) {
|
|
166
|
+
t = t[1];
|
|
167
|
+
const u = [];
|
|
168
|
+
try {
|
|
169
|
+
var m = t.replace(/'/g, '"');
|
|
170
|
+
const v = JSON.parse(m);
|
|
171
|
+
Array.isArray(v) && 0 < v.length && v.forEach(r => {
|
|
172
|
+
"string" === typeof r && u.push(r)
|
|
173
|
+
})
|
|
174
|
+
} catch (v) {
|
|
175
|
+
(m =
|
|
176
|
+
t.match(/['"]([^'"]+)['"]/g)) && m.forEach(r => {
|
|
177
|
+
u.push(r.replace(/^['"]|['"]$/g, ""))
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
if (0 < u.length) {
|
|
181
|
+
for (var n of u) {
|
|
182
|
+
d.has(n) || (d.set(n, h++), q.push(n));
|
|
183
|
+
const v = d.get(n);
|
|
184
|
+
f = n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
185
|
+
let r = !1;
|
|
186
|
+
k = new RegExp(`(title\\s*:\\s*)(['"])${f}\\2`, "gi");
|
|
187
|
+
m = new RegExp(`(title\\s*:\\s*)(\`)${f}\\2`, "gi");
|
|
188
|
+
k.test(e[l]) ? e[l] = e[l].replace(k, (w, x, y) => {
|
|
189
|
+
r = g = !0;
|
|
190
|
+
return `${x}${b}(${v})`
|
|
191
|
+
}) : m.test(e[l]) && (e[l] = e[l].replace(m, (w, x, y) => {
|
|
192
|
+
r = g = !0;
|
|
193
|
+
return `${x}${b}(${v})`
|
|
194
|
+
}));
|
|
195
|
+
if (!r) {
|
|
196
|
+
f = [new RegExp(`(["'])${f}\\1`,
|
|
197
|
+
"g"), new RegExp(`(\`)${f}\\1`, "g")];
|
|
198
|
+
for (var p of f)
|
|
199
|
+
if (p.test(e[l]) && (e[l] = e[l].replace(p, (w, x) => {
|
|
200
|
+
r = g = !0;
|
|
201
|
+
return `${b}(${v})`
|
|
202
|
+
}), r)) break
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
k || (n = f.match(/^\s*([\[\{].+?[\]\}])\s*,?\s*\/\/\s*domqGLG/)) && (k = n[1].trim());
|
|
209
|
+
k || (n = f.match(/^\s*"[^"]+":\s*(.+?)\s*,?\s*\/\/\s*domqGLG/)) && (k = n[1].trim().replace(/,\s*$/, ""));
|
|
210
|
+
k || (n = f.indexOf("// domqGLG"), 0 < n && (n = f.substring(0, n).trim(), p = n.indexOf("="), 0 <= p && (k = n.substring(p + 1).trim(), k = k.replace(/[;,]\s*$/, ""), k = k.startsWith("[") || k.startsWith("{") ? k : k.replace(/^["'`]|["'`]$/g,
|
|
211
|
+
""))), k || !(n = f.match(/=\s*(.+?)\s*[;,]?\s*\/\/\s*domqGLG/))) || (k = n[1].trim().replace(/[;,]\s*$/, ""), k = k.startsWith("[") || k.startsWith("{") ? k : k.replace(/^["'`]|["'`]$/g, ""));
|
|
212
|
+
k || (n = f.match(/(["'`])(.+?)\1/)) && (k = n[2]);
|
|
213
|
+
k || (n = f.indexOf("// domqGLG"), 0 < n && (f = f.substring(0, n).match(/['"]([^'"]+)['"][^'"]*$/)) && (k = f[1]));
|
|
214
|
+
if (k && !k.startsWith("[") && !k.startsWith("{")) {
|
|
215
|
+
d.has(k) || (d.set(k, h++), q.push(k));
|
|
216
|
+
const u = d.get(k);
|
|
217
|
+
q = k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
218
|
+
f = new RegExp(`(title\\s*:\\s*)(['"])${q}\\2`,
|
|
219
|
+
"gi");
|
|
220
|
+
k = new RegExp(`(title\\s*:\\s*)(\`)${q}\\2`, "gi");
|
|
221
|
+
let v = !1;
|
|
222
|
+
f.test(e[l]) ? e[l] = e[l].replace(f, (r, w, x) => {
|
|
223
|
+
v = g = !0;
|
|
224
|
+
return `${w}${b}(${u})`
|
|
225
|
+
}) : k.test(e[l]) && (e[l] = e[l].replace(k, (r, w, x) => {
|
|
226
|
+
v = g = !0;
|
|
227
|
+
return `${w}${b}(${u})`
|
|
228
|
+
}));
|
|
229
|
+
v || [new RegExp(`(["'])${q}\\1`, "g"), new RegExp(`(\`)${q}\\1`, "g")].forEach(r => {
|
|
230
|
+
r.test(e[l]) && (e[l] = e[l].replace(r, () => {
|
|
231
|
+
g = !0;
|
|
232
|
+
return `${b}(${u})`
|
|
233
|
+
}))
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
c = Array.from(d.keys());
|
|
239
|
+
return {
|
|
240
|
+
processedContent: g ? e.join("\n") : a,
|
|
241
|
+
extractedTexts: c
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
domquery_generateArrayVarName = a => {
|
|
245
|
+
if (!a || "string" !==
|
|
246
|
+
typeof a) return "script_txt";
|
|
247
|
+
try {
|
|
248
|
+
const b = (new URL(a, window.location.origin)).pathname.split("/").pop();
|
|
249
|
+
if (!b) return "script_txt";
|
|
250
|
+
const d = b.split(".")[0].replace(/[^a-zA-Z0-9_]/g, "_");
|
|
251
|
+
return d ? `${d}_script_txt` : "script_txt"
|
|
252
|
+
} catch (b) {
|
|
253
|
+
return "script_txt"
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
domquery_generateTranslationKey = a => a && "string" === typeof a ? "Gong_" + a.replace(/\s+/g, "_").replace(/[^\uac00-\ud7a3a-zA-Z0-9_]/g, "") : "",
|
|
257
|
+
domquery_createTranslationDiv = (a, b) => {
|
|
258
|
+
if (!a || 0 === a.length) return null;
|
|
259
|
+
if (b && "string" === typeof b) {
|
|
260
|
+
var d = b.trim();
|
|
261
|
+
d && (domquery_urlToDivMap[d] = !0)
|
|
262
|
+
}
|
|
263
|
+
b = domquery_generateArrayVarName(b);
|
|
264
|
+
const c = `domquery-${b}-data`;
|
|
265
|
+
(d = document.getElementById(c)) && d.remove();
|
|
266
|
+
d = a.map(h => ({
|
|
267
|
+
text: h,
|
|
268
|
+
key: domquery_generateTranslationKey(h)
|
|
269
|
+
}));
|
|
270
|
+
const e = document.createElement("div");
|
|
271
|
+
e.id = c;
|
|
272
|
+
e.style.display = "none";
|
|
273
|
+
e.setAttribute("data-array-name", b);
|
|
274
|
+
e.setAttribute("data-texts", JSON.stringify(a));
|
|
275
|
+
e.setAttribute("data-text-keys", JSON.stringify(d));
|
|
276
|
+
if (document.body) document.body.appendChild(e);
|
|
277
|
+
else {
|
|
278
|
+
const h = () => {
|
|
279
|
+
document.body ? document.body.appendChild(e) : setTimeout(h, 10)
|
|
280
|
+
};
|
|
281
|
+
h()
|
|
282
|
+
}
|
|
283
|
+
d =
|
|
284
|
+
`${b}_fun`;
|
|
285
|
+
const g = `${b}_data`;
|
|
286
|
+
window[g] || (window[g] = a);
|
|
287
|
+
window[d] = function(h) {
|
|
288
|
+
var f = document.getElementById(c);
|
|
289
|
+
if (f && (f = f.getAttribute("data-texts"))) try {
|
|
290
|
+
const l = JSON.parse(f);
|
|
291
|
+
return void 0 !== l[h] ? l[h] : ""
|
|
292
|
+
} catch (l) {}
|
|
293
|
+
return window[g] && void 0 !== window[g][h] ? window[g][h] : ""
|
|
294
|
+
};
|
|
295
|
+
return {
|
|
296
|
+
divId: c,
|
|
297
|
+
arrayVarName: b,
|
|
298
|
+
funName: d,
|
|
299
|
+
dataArrayName: g
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
domquery_updateTranslationDiv = (a, b) => {
|
|
303
|
+
if (!a || !b || !Array.isArray(b)) return !1;
|
|
304
|
+
var d = domquery_generateArrayVarName(a);
|
|
305
|
+
a = `${d}_data`;
|
|
306
|
+
d = document.getElementById(`domquery-${d}-data`);
|
|
307
|
+
if (!d) return !1;
|
|
308
|
+
d.setAttribute("data-texts", JSON.stringify(b));
|
|
309
|
+
window[a] && (window[a] = b);
|
|
310
|
+
if (window._domqGLGTranslationCache && (a = d.getAttribute("data-text-keys"))) try {
|
|
311
|
+
JSON.parse(a).forEach((c, e) => {
|
|
312
|
+
c.key && void 0 !== b[e] && (c = c.key.startsWith("Gong_") ? c.key : `Gong_${c.key}`, window._domqGLGTranslationCache[c] = b[e])
|
|
313
|
+
})
|
|
314
|
+
} catch (c) {}
|
|
315
|
+
return !0
|
|
316
|
+
},
|
|
317
|
+
domquery_updateTranslationDivFromJSON = (a, b) => {
|
|
318
|
+
if (!a || !b || "object" !== typeof b) return !1;
|
|
319
|
+
var d = domquery_generateArrayVarName(a);
|
|
320
|
+
d = document.getElementById(`domquery-${d}-data`);
|
|
321
|
+
if (!d) return !1;
|
|
322
|
+
d = d.getAttribute("data-text-keys");
|
|
323
|
+
if (!d) return !1;
|
|
324
|
+
d = JSON.parse(d).map(({
|
|
325
|
+
text: g,
|
|
326
|
+
key: h
|
|
327
|
+
}) => {
|
|
328
|
+
if (h = b[h]) {
|
|
329
|
+
if ("string" === typeof h && h.startsWith("[") && h.endsWith("]")) try {
|
|
330
|
+
const f = JSON.parse(h.replace(/'/g, '"'));
|
|
331
|
+
return Array.isArray(f) && 0 < f.length ? f[0] : h
|
|
332
|
+
} catch (f) {}
|
|
333
|
+
return h
|
|
334
|
+
}
|
|
335
|
+
return g
|
|
336
|
+
});
|
|
337
|
+
if (!domquery_updateTranslationDiv(a, d)) return !1;
|
|
338
|
+
let c = 0;
|
|
339
|
+
const e = () => {
|
|
340
|
+
"function" === typeof window.domquery_convertDataArrayPropertiesAfterTranslation ? window.domquery_convertDataArrayPropertiesAfterTranslation() : 10 >
|
|
341
|
+
c && (c++, setTimeout(e, 50))
|
|
342
|
+
};
|
|
343
|
+
setTimeout(e, 50);
|
|
344
|
+
return !0
|
|
345
|
+
},
|
|
346
|
+
domquery_updateAllTranslationDivs = a => {
|
|
347
|
+
if (!a || "object" !== typeof a) return !1;
|
|
348
|
+
let b = 0,
|
|
349
|
+
d = 0;
|
|
350
|
+
Object.keys(a).forEach(c => {
|
|
351
|
+
domquery_updateTranslationDiv(c, a[c]) ? b++ : d++
|
|
352
|
+
});
|
|
353
|
+
return {
|
|
354
|
+
success: b,
|
|
355
|
+
failed: d
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
window.domquery_updateTranslationDiv = domquery_updateTranslationDiv;
|
|
359
|
+
window.domquery_updateAllTranslationDivs = domquery_updateAllTranslationDivs;
|
|
360
|
+
window.domquery_updateTranslationDivFromJSON = domquery_updateTranslationDivFromJSON;
|
|
361
|
+
window.domquery_loadTranslationAndUpdate = function(a, b) {
|
|
362
|
+
$.ajax({
|
|
363
|
+
url: b,
|
|
364
|
+
dataType: "json",
|
|
365
|
+
success: function(d) {
|
|
366
|
+
domquery_updateTranslationDivFromJSON(a, d)
|
|
367
|
+
},
|
|
368
|
+
error: function(d, c, e) {}
|
|
369
|
+
})
|
|
370
|
+
};
|
|
371
|
+
const domquery_loadAndExecuteScripts = (a, b) => {
|
|
372
|
+
if (a && Array.isArray(a)) {
|
|
373
|
+
var d = [],
|
|
374
|
+
c = [];
|
|
375
|
+
a.forEach(e => {
|
|
376
|
+
try {
|
|
377
|
+
if ("undefined" !== typeof localStorage) {
|
|
378
|
+
var g = localStorage.getItem(e);
|
|
379
|
+
if (g) {
|
|
380
|
+
const f = JSON.parse(g);
|
|
381
|
+
if (Date.now() - f.timestamp > domquery_SCRIPT_STORAGE_EXPIRY) localStorage.removeItem(e);
|
|
382
|
+
else {
|
|
383
|
+
try {
|
|
384
|
+
localStorage.removeItem(e)
|
|
385
|
+
} catch (l) {}
|
|
386
|
+
if (f.content) {
|
|
387
|
+
const l = domquery_generateArrayVarName(b || f.originalUrl || "");
|
|
388
|
+
g = `${l}_fun`;
|
|
389
|
+
var h = domquery_processScriptWithFunctionCall(f.content, g);
|
|
390
|
+
d.push(...h.extractedTexts);
|
|
391
|
+
let k =
|
|
392
|
+
h.processedContent;
|
|
393
|
+
const q = k.split("\n");
|
|
394
|
+
h = [];
|
|
395
|
+
for (let t = 0; t < q.length; t++) {
|
|
396
|
+
const m = q[t],
|
|
397
|
+
n = m.match(/(?:const|let|var)\s+(\w+Data)\s*=\s*\[/);
|
|
398
|
+
if (n) {
|
|
399
|
+
const p = n[1];
|
|
400
|
+
(new RegExp(`window\\.${p}\\s*=`, "g")).test(k) || h.push({
|
|
401
|
+
lineIndex: t,
|
|
402
|
+
varName: p,
|
|
403
|
+
line: m
|
|
404
|
+
})
|
|
405
|
+
}
|
|
406
|
+
if (0 < h.length) {
|
|
407
|
+
const p = h[h.length - 1];
|
|
408
|
+
m.includes("];") && t > p.lineIndex && (q.splice(t + 1, 0, ` window.${p.varName} = ${p.varName};`), h.pop(), t++)
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
k = q.join("\n");
|
|
412
|
+
c.push({
|
|
413
|
+
storageKey: e,
|
|
414
|
+
scriptData: f,
|
|
415
|
+
processedContent: k,
|
|
416
|
+
arrayVarName: l,
|
|
417
|
+
funName: g,
|
|
418
|
+
originalContent: f.content
|
|
419
|
+
})
|
|
420
|
+
} else f.src &&
|
|
421
|
+
c.push({
|
|
422
|
+
storageKey: e,
|
|
423
|
+
scriptData: f,
|
|
424
|
+
processedContent: null,
|
|
425
|
+
arrayVarName: null,
|
|
426
|
+
funName: null,
|
|
427
|
+
originalContent: null
|
|
428
|
+
})
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
} catch (f) {}
|
|
433
|
+
});
|
|
434
|
+
0 < d.length && (a = [...(new Set(d))], domquery_createTranslationDiv(a, b));
|
|
435
|
+
c.forEach(({
|
|
436
|
+
storageKey: e,
|
|
437
|
+
scriptData: g,
|
|
438
|
+
processedContent: h,
|
|
439
|
+
funName: f,
|
|
440
|
+
originalContent: l
|
|
441
|
+
}) => {
|
|
442
|
+
try {
|
|
443
|
+
const k = document.createElement("script");
|
|
444
|
+
k.type = g.type;
|
|
445
|
+
k.async = g.async;
|
|
446
|
+
k.defer = g.defer;
|
|
447
|
+
g.src ? k.src = g.src : null !== h && (k.textContent = h);
|
|
448
|
+
k.onload = () => {
|
|
449
|
+
var t = domquery_scriptRegistry.get(e);
|
|
450
|
+
t && (t.state = domquery_SCRIPT_STATES.EXECUTED,
|
|
451
|
+
t.executedAt = Date.now());
|
|
452
|
+
if (h && f && l) {
|
|
453
|
+
t = new RegExp(`title:\\s*${f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\((\\d+)\\)`, "g");
|
|
454
|
+
const m = [...h.matchAll(t)];
|
|
455
|
+
0 < m.length && setTimeout(() => {
|
|
456
|
+
try {
|
|
457
|
+
for (const n in window)
|
|
458
|
+
if (n.endsWith("Data") && Array.isArray(window[n])) {
|
|
459
|
+
const p = window[n];
|
|
460
|
+
m.forEach(u => {
|
|
461
|
+
const v = parseInt(u[1]);
|
|
462
|
+
if (v < p.length && p[v] && "object" === typeof p[v] && (u = p[v], "title" in u)) {
|
|
463
|
+
const r = u.title;
|
|
464
|
+
Object.defineProperty(u, "title", {
|
|
465
|
+
get: function() {
|
|
466
|
+
if ("function" === typeof window[f]) try {
|
|
467
|
+
return window[f](v) || r
|
|
468
|
+
} catch (w) {}
|
|
469
|
+
return r
|
|
470
|
+
},
|
|
471
|
+
enumerable: !0,
|
|
472
|
+
configurable: !0
|
|
473
|
+
})
|
|
474
|
+
}
|
|
475
|
+
})
|
|
476
|
+
}
|
|
477
|
+
} catch (n) {}
|
|
478
|
+
}, 100)
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
k.onerror = () => {
|
|
482
|
+
const t = domquery_scriptRegistry.get(e);
|
|
483
|
+
t && (t.state = domquery_SCRIPT_STATES.ERROR, t.errorAt = Date.now())
|
|
484
|
+
};
|
|
485
|
+
document.head.appendChild(k);
|
|
486
|
+
let q = domquery_scriptRegistry.get(e);
|
|
487
|
+
q && (q.state = domquery_SCRIPT_STATES.LOADED, q.loadedAt = Date.now())
|
|
488
|
+
} catch (k) {}
|
|
489
|
+
})
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
domquery_cleanupExpiredScripts = () => {
|
|
493
|
+
if ("undefined" !== typeof localStorage) try {
|
|
494
|
+
const a = Object.keys(localStorage).filter(e => e.startsWith(domquery_SCRIPT_STORAGE_PREFIX));
|
|
495
|
+
let b = 0;
|
|
496
|
+
const d =
|
|
497
|
+
Date.now();
|
|
498
|
+
a.forEach(e => {
|
|
499
|
+
try {
|
|
500
|
+
if (e.includes("_src_") || e.includes("_content_")) {
|
|
501
|
+
var g = localStorage.getItem(e);
|
|
502
|
+
if (g) {
|
|
503
|
+
const h = JSON.parse(g);
|
|
504
|
+
d - h.timestamp > domquery_SCRIPT_STORAGE_EXPIRY && (localStorage.removeItem(e), b++)
|
|
505
|
+
} else localStorage.removeItem(e), b++
|
|
506
|
+
} else localStorage.removeItem(e), b++
|
|
507
|
+
} catch (h) {
|
|
508
|
+
localStorage.removeItem(e), b++
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
0 < b && a.forEach(e => {
|
|
512
|
+
localStorage.getItem(e) || domquery_scriptRegistry.delete(e)
|
|
513
|
+
});
|
|
514
|
+
const c = Date.now();
|
|
515
|
+
for (const [e, g] of domquery_scriptRegistry.entries()) g.state === domquery_SCRIPT_STATES.EXECUTED &&
|
|
516
|
+
g.executedAt ? 36E5 < c - g.executedAt && domquery_scriptRegistry.delete(e) : g.state === domquery_SCRIPT_STATES.ERROR && g.errorAt ? 36E5 < c - g.errorAt && domquery_scriptRegistry.delete(e) : g.registeredAt && 36E5 < c - g.registeredAt && domquery_scriptRegistry.delete(e)
|
|
517
|
+
} catch (a) {}
|
|
518
|
+
},
|
|
519
|
+
generateUUID = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(a) {
|
|
520
|
+
const b = 16 * Math.random() | 0;
|
|
521
|
+
return ("x" === a ? b : b & 3 | 8).toString(16)
|
|
522
|
+
}),
|
|
523
|
+
generateCallbackName = (a = AJAX_CONFIG.CALLBACK_PREFIX) => a + Date.now() + "_" + generateUUID().substring(0,
|
|
524
|
+
8),
|
|
525
|
+
parseXML = a => (new DOMParser).parseFromString(a, "text/xml"),
|
|
526
|
+
callAjaxEvent = (a, b, d, c) => {
|
|
527
|
+
if (a && "function" === typeof a) try {
|
|
528
|
+
a(b, d, c)
|
|
529
|
+
} catch (e) {}
|
|
530
|
+
},
|
|
531
|
+
createXhrData = (a, b) => a || b ? {
|
|
532
|
+
readyState: a ? 4 : 0,
|
|
533
|
+
status: a ? a.status : 0,
|
|
534
|
+
statusText: a ? a.statusText : b ? b.message : "",
|
|
535
|
+
responseText: a && a.text ? a.text : "",
|
|
536
|
+
responseXML: a && a.text && a.headers && a.headers.get("content-type")?.includes("xml") ? parseXML(a.text) : null,
|
|
537
|
+
getResponseHeader: d => a ? a.headers.get(d) : null,
|
|
538
|
+
getAllResponseHeaders: () => {
|
|
539
|
+
if (!a || !a.headers) return "";
|
|
540
|
+
let d = "";
|
|
541
|
+
for (const [c,
|
|
542
|
+
e
|
|
543
|
+
] of a.headers.entries()) d += `${c}: ${e}\r\n`;
|
|
544
|
+
return d
|
|
545
|
+
},
|
|
546
|
+
setRequestHeader: () => {},
|
|
547
|
+
overrideMimeType: () => {}
|
|
548
|
+
} : null,
|
|
549
|
+
isFileUrl = a => a ? ["file://", "content://", "android_asset://"].some(b => a.toLowerCase().startsWith(b)) : !1,
|
|
550
|
+
detectAvailableBridges = () => {
|
|
551
|
+
const a = [];
|
|
552
|
+
for (const b of AJAX_CONFIG.BRIDGE.ANDROID_BRIDGES) window[b.name] && window[b.name][b.method] && a.push({
|
|
553
|
+
type: "android",
|
|
554
|
+
name: b.name,
|
|
555
|
+
method: b.method,
|
|
556
|
+
priority: b.priority,
|
|
557
|
+
available: !0
|
|
558
|
+
});
|
|
559
|
+
window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.httpRequest &&
|
|
560
|
+
a.push({
|
|
561
|
+
type: "ios",
|
|
562
|
+
name: "webkit.messageHandlers",
|
|
563
|
+
method: "httpRequest",
|
|
564
|
+
priority: AJAX_CONFIG.BRIDGE.IOS_BRIDGE.priority,
|
|
565
|
+
available: !0
|
|
566
|
+
});
|
|
567
|
+
return a.sort((b, d) => b.priority - d.priority)
|
|
568
|
+
},
|
|
569
|
+
detectEnvironmentAjax = (a, b = null) => {
|
|
570
|
+
if (isFileUrl(a)) return a = detectAvailableBridges(), 0 < a.length ? {
|
|
571
|
+
type: "webview_bridge",
|
|
572
|
+
bridges: a,
|
|
573
|
+
reason: "file_url_detected"
|
|
574
|
+
} : {
|
|
575
|
+
type: "webview_bridge_required",
|
|
576
|
+
bridges: [],
|
|
577
|
+
reason: "file_url_no_bridge"
|
|
578
|
+
};
|
|
579
|
+
if (b && ("android" === b || "ios" === b)) return {
|
|
580
|
+
type: "webview_bridge",
|
|
581
|
+
bridges: detectAvailableBridges().filter(d =>
|
|
582
|
+
d.type === b),
|
|
583
|
+
reason: "forced_app_setting"
|
|
584
|
+
};
|
|
585
|
+
a = detectAvailableBridges();
|
|
586
|
+
return 0 < a.length ? {
|
|
587
|
+
type: "webview_bridge",
|
|
588
|
+
bridges: a,
|
|
589
|
+
reason: "bridge_available"
|
|
590
|
+
} : {
|
|
591
|
+
type: "web",
|
|
592
|
+
bridges: [],
|
|
593
|
+
reason: "no_bridge_detected"
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
prepareBridgeData = a => ({
|
|
597
|
+
url: a.url,
|
|
598
|
+
method: a.method || "GET",
|
|
599
|
+
data: a.data || {},
|
|
600
|
+
headers: a.headers || {},
|
|
601
|
+
timeout: isFileUrl(a.url) ? AJAX_CONFIG.FILE_URL_HANDLING.ENHANCED_TIMEOUT : a.timeout,
|
|
602
|
+
dataType: a.dataType || "text"
|
|
603
|
+
}),
|
|
604
|
+
executeAndroidBridge = (a, b) => new Promise((d, c) => {
|
|
605
|
+
const e = window[a.name];
|
|
606
|
+
let g = setTimeout(() => {
|
|
607
|
+
c(Error("Android bridge timeout"))
|
|
608
|
+
},
|
|
609
|
+
b.timeout || AJAX_CONFIG.DEFAULT_TIMEOUT);
|
|
610
|
+
const h = () => {
|
|
611
|
+
g && (clearTimeout(g), g = null)
|
|
612
|
+
};
|
|
613
|
+
try {
|
|
614
|
+
if ("AndroidBridge" === a.name && e.httpRequest) {
|
|
615
|
+
const f = generateCallbackName(AJAX_CONFIG.SUCCESS_CALLBACK_PREFIX),
|
|
616
|
+
l = generateCallbackName(AJAX_CONFIG.ERROR_CALLBACK_PREFIX);
|
|
617
|
+
window[f] = function(k) {
|
|
618
|
+
h();
|
|
619
|
+
try {
|
|
620
|
+
const q = "string" === typeof k ? JSON.parse(k) : k;
|
|
621
|
+
delete window[f];
|
|
622
|
+
delete window[l];
|
|
623
|
+
d(q.data || q)
|
|
624
|
+
} catch (q) {
|
|
625
|
+
c(q)
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
window[l] = function(k) {
|
|
629
|
+
h();
|
|
630
|
+
delete window[f];
|
|
631
|
+
delete window[l];
|
|
632
|
+
c(Error(k.message || k))
|
|
633
|
+
};
|
|
634
|
+
e.httpRequest(JSON.stringify(b),
|
|
635
|
+
f, l)
|
|
636
|
+
} else if ("Android" === a.name && e.httpRequest) {
|
|
637
|
+
const f = e.httpRequest(JSON.stringify(b));
|
|
638
|
+
h();
|
|
639
|
+
const l = JSON.parse(f);
|
|
640
|
+
d(l.data || l)
|
|
641
|
+
} else h(), c(Error(`Android bridge method not found: ${a.name}.${a.method}`))
|
|
642
|
+
} catch (f) {
|
|
643
|
+
h(), c(f)
|
|
644
|
+
}
|
|
645
|
+
}),
|
|
646
|
+
executeIosBridge = (a, b) => new Promise((d, c) => {
|
|
647
|
+
const e = b.timeout || AJAX_CONFIG.DEFAULT_TIMEOUT,
|
|
648
|
+
g = generateCallbackName(AJAX_CONFIG.REQUEST_PREFIX);
|
|
649
|
+
let h = setTimeout(() => {
|
|
650
|
+
f();
|
|
651
|
+
c(Error("iOS bridge timeout"))
|
|
652
|
+
}, e);
|
|
653
|
+
const f = () => {
|
|
654
|
+
h && (clearTimeout(h), h = null);
|
|
655
|
+
delete window[AJAX_CONFIG.HTTP_RESPONSE_PREFIX +
|
|
656
|
+
g];
|
|
657
|
+
delete window[AJAX_CONFIG.HTTP_ERROR_PREFIX + g]
|
|
658
|
+
};
|
|
659
|
+
try {
|
|
660
|
+
window[AJAX_CONFIG.HTTP_RESPONSE_PREFIX + g] = function(l) {
|
|
661
|
+
f();
|
|
662
|
+
try {
|
|
663
|
+
const k = "string" === typeof l ? JSON.parse(l) : l;
|
|
664
|
+
d(k.data || k)
|
|
665
|
+
} catch (k) {
|
|
666
|
+
c(k)
|
|
667
|
+
}
|
|
668
|
+
}, window[AJAX_CONFIG.HTTP_ERROR_PREFIX + g] = function(l) {
|
|
669
|
+
f();
|
|
670
|
+
c(Error(l.message || l))
|
|
671
|
+
}, window.webkit.messageHandlers.httpRequest.postMessage({
|
|
672
|
+
...b,
|
|
673
|
+
requestId: g
|
|
674
|
+
})
|
|
675
|
+
} catch (l) {
|
|
676
|
+
f(), c(l)
|
|
677
|
+
}
|
|
678
|
+
}),
|
|
679
|
+
executeWebViewBridge = async (a, b) => {
|
|
680
|
+
const d = isFileUrl(a.url);
|
|
681
|
+
if (!b.bridges || 0 === b.bridges.length) {
|
|
682
|
+
if (d) throw Error("No WebView bridges available. File URL requires WebView bridge.");
|
|
683
|
+
throw Error("No WebView bridges available");
|
|
684
|
+
}
|
|
685
|
+
a = prepareBridgeData(a);
|
|
686
|
+
for (const c of b.bridges) try {
|
|
687
|
+
let e;
|
|
688
|
+
if ("android" === c.type) e = await executeAndroidBridge(c, a);
|
|
689
|
+
else if ("ios" === c.type) e = await executeIosBridge(c, a);
|
|
690
|
+
else throw Error(`Unsupported bridge type: ${c.type}`);
|
|
691
|
+
return e
|
|
692
|
+
} catch (e) {
|
|
693
|
+
if (!d) throw e;
|
|
694
|
+
}
|
|
695
|
+
throw Error(`All WebView bridges failed for ${d?"file":"HTTP"} URL`);
|
|
696
|
+
}, handleCustomBridge = (a, b) => {
|
|
697
|
+
const d = customBridges.get(a);
|
|
698
|
+
return d && d.ajax ? new Promise((c, e) => {
|
|
699
|
+
let g = null;
|
|
700
|
+
0 < b.timeout && (g = setTimeout(() => {
|
|
701
|
+
e(Error("Custom bridge timeout"))
|
|
702
|
+
}, b.timeout));
|
|
703
|
+
try {
|
|
704
|
+
callAjaxEvent(b.ajaxStart, null, null, b);
|
|
705
|
+
callAjaxEvent(b.ajaxSend, null, null, b);
|
|
706
|
+
const h = d.ajax(b);
|
|
707
|
+
h && "function" === typeof h.then ? h.then(f => {
|
|
708
|
+
g && (clearTimeout(g), g = null);
|
|
709
|
+
const l = createXhrData({
|
|
710
|
+
status: f.status || 200,
|
|
711
|
+
statusText: f.statusText || "OK",
|
|
712
|
+
text: f.data || f,
|
|
713
|
+
headers: new Headers(f.headers || {})
|
|
714
|
+
}, null);
|
|
715
|
+
callAjaxEvent(b.ajaxSuccess, f.data || f, "success", l);
|
|
716
|
+
callAjaxEvent(b.success, f.data || f, "success", l);
|
|
717
|
+
callAjaxEvent(b.complete, l, "success");
|
|
718
|
+
callAjaxEvent(b.ajaxStop);
|
|
719
|
+
c(f.data || f)
|
|
720
|
+
}).catch(f => {
|
|
721
|
+
g && (clearTimeout(g), g = null);
|
|
722
|
+
const l = createXhrData(null, f);
|
|
723
|
+
callAjaxEvent(b.ajaxError, l, "error", f);
|
|
724
|
+
callAjaxEvent(b.error, l, "error", f);
|
|
725
|
+
callAjaxEvent(b.complete, l, "error");
|
|
726
|
+
callAjaxEvent(b.ajaxStop);
|
|
727
|
+
e(f)
|
|
728
|
+
}) : (g && (clearTimeout(g), g = null), e(Error("Custom bridge must return a Promise")))
|
|
729
|
+
} catch (h) {
|
|
730
|
+
g && (clearTimeout(g), g = null), e(h)
|
|
731
|
+
}
|
|
732
|
+
}) : Promise.reject(Error(`Custom bridge ${a} not available`))
|
|
733
|
+
};
|
|
734
|
+
$.ajax = function(a, b) {
|
|
735
|
+
function d() {
|
|
736
|
+
callAjaxEvent(c.ajaxStart, null, null, c);
|
|
737
|
+
return "jsonp" === c.dataType ? (callAjaxEvent(c.ajaxSend, null, null, c), new Promise((g, h) => {
|
|
738
|
+
const f = (new URLSearchParams(c.data)).toString(),
|
|
739
|
+
l = "function" === typeof c.jsonpCallback ? c.jsonpCallback() : c.jsonpCallback,
|
|
740
|
+
k = encodeURIComponent(l),
|
|
741
|
+
q = window[l],
|
|
742
|
+
t = "function" === typeof q,
|
|
743
|
+
m = document.createElement("script"),
|
|
744
|
+
n = c.url.includes("?") ? "&" : "?";
|
|
745
|
+
m.src = `${c.url}${n}${f}&callback=${k}`;
|
|
746
|
+
let p = null;
|
|
747
|
+
0 < c.timeout && (p = setTimeout(() => {
|
|
748
|
+
u(Error("Timeout"),
|
|
749
|
+
"timeout")
|
|
750
|
+
}, c.timeout));
|
|
751
|
+
const u = (r, w) => {
|
|
752
|
+
p && clearTimeout(p);
|
|
753
|
+
const x = createXhrData(null, r);
|
|
754
|
+
callAjaxEvent(c.ajaxError, x, w || "error", r);
|
|
755
|
+
callAjaxEvent(c.error, x, w || "error", r);
|
|
756
|
+
v();
|
|
757
|
+
callAjaxEvent(c.complete, x, w || "error");
|
|
758
|
+
callAjaxEvent(c.ajaxStop);
|
|
759
|
+
h(r)
|
|
760
|
+
},
|
|
761
|
+
v = () => {
|
|
762
|
+
try {
|
|
763
|
+
t ? window[l] = q : delete window[l], m.parentNode && m.parentNode.removeChild(m)
|
|
764
|
+
} catch (r) {}
|
|
765
|
+
};
|
|
766
|
+
window[l] = function(r) {
|
|
767
|
+
try {
|
|
768
|
+
t && q(r);
|
|
769
|
+
p && clearTimeout(p);
|
|
770
|
+
const w = createXhrData({
|
|
771
|
+
status: 200,
|
|
772
|
+
statusText: "OK",
|
|
773
|
+
text: "string" === typeof r ? r : JSON.stringify(r),
|
|
774
|
+
headers: new Headers
|
|
775
|
+
},
|
|
776
|
+
null);
|
|
777
|
+
callAjaxEvent(c.ajaxSuccess, r, "success", w);
|
|
778
|
+
callAjaxEvent(c.success, r, "success", w);
|
|
779
|
+
v();
|
|
780
|
+
callAjaxEvent(c.complete, w, "success");
|
|
781
|
+
callAjaxEvent(c.ajaxStop);
|
|
782
|
+
g(r)
|
|
783
|
+
} catch (w) {
|
|
784
|
+
u(w, "error")
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
m.onerror = function(r) {
|
|
788
|
+
u(Error("Script loading error"), "error")
|
|
789
|
+
};
|
|
790
|
+
document.head.appendChild(m)
|
|
791
|
+
})) : new Promise((g, h) => {
|
|
792
|
+
var f = c.method;
|
|
793
|
+
let l = c.url,
|
|
794
|
+
k = {
|
|
795
|
+
method: f,
|
|
796
|
+
headers: new Headers(c.headers),
|
|
797
|
+
cache: c.cache ? "default" : "no-store",
|
|
798
|
+
credentials: c.crossDomain ? "omit" : "same-origin"
|
|
799
|
+
};
|
|
800
|
+
!1 !== c.contentType && k.headers.set("Content-Type",
|
|
801
|
+
c.contentType);
|
|
802
|
+
if ("GET" === f && c.data)
|
|
803
|
+
if ("string" === typeof c.data) l += (l.includes("?") ? "&" : "?") + c.data;
|
|
804
|
+
else {
|
|
805
|
+
if ("object" === typeof c.data) {
|
|
806
|
+
f = new URLSearchParams;
|
|
807
|
+
for (const [m, n] of Object.entries(c.data)) f.append(m, n);
|
|
808
|
+
l += (l.includes("?") ? "&" : "?") + f.toString()
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
else if ("POST" === f || "PUT" === f || "PATCH" === f || "DELETE" === f) {
|
|
812
|
+
if (c.url.includes(AJAX_CONFIG.TEST_URL_PATTERN)) {
|
|
813
|
+
setTimeout(() => {
|
|
814
|
+
let m = "";
|
|
815
|
+
this.elements && this.elements.length ? this.elements.forEach(function(p, u) {
|
|
816
|
+
p && p.files && p.files[0] && (m && (m += "\n\n"), m +=
|
|
817
|
+
`file_name: file${u}\nfile_value: ${p.files[0].name}`)
|
|
818
|
+
}) : m = "Demo response data";
|
|
819
|
+
const n = {
|
|
820
|
+
readyState: 4,
|
|
821
|
+
status: 200,
|
|
822
|
+
statusText: "OK",
|
|
823
|
+
responseText: m,
|
|
824
|
+
responseXML: null,
|
|
825
|
+
getResponseHeader: () => null,
|
|
826
|
+
getAllResponseHeaders: () => ""
|
|
827
|
+
};
|
|
828
|
+
callAjaxEvent(c.ajaxSuccess, m, "success", n);
|
|
829
|
+
callAjaxEvent(c.success, m, "success", n);
|
|
830
|
+
g(m);
|
|
831
|
+
callAjaxEvent(c.complete, n, "success");
|
|
832
|
+
callAjaxEvent(c.ajaxStop)
|
|
833
|
+
}, AJAX_CONFIG.BRIDGE_FALLBACK_DELAY);
|
|
834
|
+
return
|
|
835
|
+
}
|
|
836
|
+
if (c.data instanceof FormData) k.body = c.data, k.headers.delete("Content-Type");
|
|
837
|
+
else if ("string" ===
|
|
838
|
+
typeof c.data) k.body = c.data;
|
|
839
|
+
else if ("object" === typeof c.data)
|
|
840
|
+
if (!1 !== c.processData) {
|
|
841
|
+
f = new URLSearchParams;
|
|
842
|
+
for (const [m, n] of Object.entries(c.data)) f.append(m, n);
|
|
843
|
+
k.body = f.toString()
|
|
844
|
+
} else {
|
|
845
|
+
f = new FormData;
|
|
846
|
+
for (const [m, n] of Object.entries(c.data)) f.append(m, n);
|
|
847
|
+
k.body = f;
|
|
848
|
+
k.headers.delete("Content-Type")
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
callAjaxEvent(c.ajaxSend, null, null, k);
|
|
852
|
+
let q = null;
|
|
853
|
+
const t = new AbortController;
|
|
854
|
+
k.signal = t.signal;
|
|
855
|
+
0 < c.timeout && (q = setTimeout(() => {
|
|
856
|
+
t.abort()
|
|
857
|
+
}, c.timeout));
|
|
858
|
+
fetch(l, k).then(m => {
|
|
859
|
+
q && clearTimeout(q);
|
|
860
|
+
if (!m.ok) throw Error(`HTTP error! status: ${m.status}`);
|
|
861
|
+
const n = m.headers.get("content-type") || "";
|
|
862
|
+
return ("json" === c.dataType || n.includes("application/json") ? m.text().then(p => {
|
|
863
|
+
try {
|
|
864
|
+
return p ? JSON.parse(p) : null
|
|
865
|
+
} catch (u) {
|
|
866
|
+
throw Error(`JSON parse error: ${u.message}`);
|
|
867
|
+
}
|
|
868
|
+
}).catch(p => {
|
|
869
|
+
throw p;
|
|
870
|
+
}) : "xml" === c.dataType || n.includes("xml") ? m.text().then(p => parseXML(p)) : m.text()).then(p => ({
|
|
871
|
+
data: p,
|
|
872
|
+
response: m
|
|
873
|
+
}))
|
|
874
|
+
}).then(({
|
|
875
|
+
data: m,
|
|
876
|
+
response: n
|
|
877
|
+
}) => {
|
|
878
|
+
let p = m,
|
|
879
|
+
u = null;
|
|
880
|
+
c.script && "string" === typeof m && m.includes("<script") && (m = domquery_extractAndStoreScripts(m, c.url), p = m.cleanHtml, u = m.storageKeys);
|
|
881
|
+
n = createXhrData(n, null);
|
|
882
|
+
n.responseText = "string" === typeof p ? p : JSON.stringify(p);
|
|
883
|
+
callAjaxEvent(c.ajaxSuccess, p, "success", n);
|
|
884
|
+
callAjaxEvent(c.success, p, "success", n);
|
|
885
|
+
callAjaxEvent(c.complete, n, "success");
|
|
886
|
+
callAjaxEvent(c.ajaxStop);
|
|
887
|
+
u && 0 < u.length && setTimeout(() => {
|
|
888
|
+
domquery_loadAndExecuteScripts(u, c.url)
|
|
889
|
+
}, 0);
|
|
890
|
+
g(p)
|
|
891
|
+
}).catch(m => {
|
|
892
|
+
q && clearTimeout(q);
|
|
893
|
+
const n = "AbortError" === m.name ? "timeout" : "error",
|
|
894
|
+
p = createXhrData(null, m);
|
|
895
|
+
callAjaxEvent(c.ajaxError, p, n, m);
|
|
896
|
+
callAjaxEvent(c.error, p, n, m);
|
|
897
|
+
callAjaxEvent(c.complete, p, n);
|
|
898
|
+
callAjaxEvent(c.ajaxStop);
|
|
899
|
+
h(m)
|
|
900
|
+
})
|
|
901
|
+
})
|
|
902
|
+
}
|
|
903
|
+
const c = {
|
|
904
|
+
url: a.url || "",
|
|
905
|
+
method: (a.method || (1 === b ? "POST" : 2 === b ? "GET" : "POST")).toUpperCase(),
|
|
906
|
+
dataType: (a.dataType || "*").toLowerCase(),
|
|
907
|
+
data: a.data || {},
|
|
908
|
+
headers: a.headers || {},
|
|
909
|
+
processData: void 0 !== a.processData ? a.processData : !0,
|
|
910
|
+
contentType: void 0 !== a.contentType ? a.contentType : AJAX_CONFIG.DEFAULT_CONTENT_TYPE,
|
|
911
|
+
async: void 0 !== a.async ? a.async : !0,
|
|
912
|
+
cache: void 0 !== a.cache ? a.cache : !0,
|
|
913
|
+
jsonpCallback: a.jsonpCallback || AJAX_CONFIG.JSONP_CALLBACK_PREFIX + Math.round(1E5 * Math.random()),
|
|
914
|
+
timeout: a.timeout || AJAX_CONFIG.DEFAULT_TIMEOUT,
|
|
915
|
+
crossDomain: void 0 !== a.crossDomain ? a.crossDomain : !0,
|
|
916
|
+
app: a.app,
|
|
917
|
+
script: a.script || !1,
|
|
918
|
+
ajaxStart: a.ajaxStart,
|
|
919
|
+
ajaxSend: a.ajaxSend,
|
|
920
|
+
ajaxSuccess: a.ajaxSuccess,
|
|
921
|
+
ajaxError: a.ajaxError,
|
|
922
|
+
ajaxComplete: a.ajaxComplete || a.complete,
|
|
923
|
+
ajaxStop: a.ajaxStop,
|
|
924
|
+
success: a.success,
|
|
925
|
+
error: a.error,
|
|
926
|
+
complete: a.complete
|
|
927
|
+
},
|
|
928
|
+
e = isFileUrl(c.url);
|
|
929
|
+
a = detectEnvironmentAjax(c.url, c.app);
|
|
930
|
+
return 0 < customBridges.size && (b = Array.from(customBridges.keys()).filter(g => (g = customBridges.get(g)) && g.isAvailable && g.isAvailable()), 0 < b.length) ? handleCustomBridge(b[0],
|
|
931
|
+
c) : "webview_bridge" === a.type || "webview_bridge_required" === a.type ? (callAjaxEvent(c.ajaxStart, null, null, c), callAjaxEvent(c.ajaxSend, null, null, c), executeWebViewBridge(c, a).then(g => {
|
|
932
|
+
let h = g,
|
|
933
|
+
f = null;
|
|
934
|
+
c.script && "string" === typeof g && g.includes("<script") && (g = domquery_extractAndStoreScripts(g, c.url), h = g.cleanHtml, f = g.storageKeys);
|
|
935
|
+
g = createXhrData({
|
|
936
|
+
status: 200,
|
|
937
|
+
statusText: "OK",
|
|
938
|
+
text: h,
|
|
939
|
+
headers: new Headers
|
|
940
|
+
}, null);
|
|
941
|
+
callAjaxEvent(c.ajaxSuccess, h, "success", g);
|
|
942
|
+
callAjaxEvent(c.success, h, "success", g);
|
|
943
|
+
callAjaxEvent(c.complete,
|
|
944
|
+
g, "success");
|
|
945
|
+
callAjaxEvent(c.ajaxStop);
|
|
946
|
+
f && 0 < f.length && setTimeout(() => {
|
|
947
|
+
domquery_loadAndExecuteScripts(f, c.url)
|
|
948
|
+
}, 0);
|
|
949
|
+
return h
|
|
950
|
+
}).catch(g => {
|
|
951
|
+
const h = createXhrData(null, g);
|
|
952
|
+
callAjaxEvent(c.ajaxError, h, "error", g);
|
|
953
|
+
callAjaxEvent(c.error, h, "error", g);
|
|
954
|
+
callAjaxEvent(c.complete, h, "error");
|
|
955
|
+
callAjaxEvent(c.ajaxStop);
|
|
956
|
+
if (e && AJAX_CONFIG.FILE_URL_HANDLING.DISABLE_FALLBACK) throw Error(`File URL access failed: ${g.message}. WebView Bridge required.`);
|
|
957
|
+
if (!e) return d();
|
|
958
|
+
throw g;
|
|
959
|
+
})) : d()
|
|
960
|
+
};
|
|
961
|
+
$.registerCustomBridge = function(a, b) {
|
|
962
|
+
if (!a || "string" !== typeof a) throw Error("Bridge name must be a non-empty string");
|
|
963
|
+
if (!b || "object" !== typeof b) throw Error("Bridge interface must be an object");
|
|
964
|
+
if (!b.ajax || "function" !== typeof b.ajax) throw Error("Bridge interface must have an ajax function");
|
|
965
|
+
b.isAvailable || (b.isAvailable = () => !0);
|
|
966
|
+
customBridges.set(a, b);
|
|
967
|
+
return !0
|
|
968
|
+
};
|
|
969
|
+
$.unregisterCustomBridge = function(a) {
|
|
970
|
+
return customBridges.has(a) ? (customBridges.delete(a), !0) : !1
|
|
971
|
+
};
|
|
972
|
+
$.getCustomBridges = function() {
|
|
973
|
+
return Array.from(customBridges.keys())
|
|
974
|
+
};
|
|
975
|
+
$.getCustomBridgeInfo = function(a) {
|
|
976
|
+
const b = customBridges.get(a);
|
|
977
|
+
return b ? {
|
|
978
|
+
name: a,
|
|
979
|
+
available: b.isAvailable ? b.isAvailable() : !0,
|
|
980
|
+
hasAjax: "function" === typeof b.ajax,
|
|
981
|
+
description: b.description || "No description provided"
|
|
982
|
+
} : null
|
|
983
|
+
};
|
|
984
|
+
$.getAllBridgesStatus = function() {
|
|
985
|
+
const a = detectAvailableBridges(),
|
|
986
|
+
b = [];
|
|
987
|
+
for (const [d, c] of customBridges.entries()) b.push({
|
|
988
|
+
name: d,
|
|
989
|
+
available: c.isAvailable ? c.isAvailable() : !0,
|
|
990
|
+
priority: bridgePriority.custom
|
|
991
|
+
});
|
|
992
|
+
return {
|
|
993
|
+
environment: 0 < a.length ? "webview" : "web",
|
|
994
|
+
standardBridges: a,
|
|
995
|
+
customBridges: b
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
$.post = function(a, b, d, c) {
|
|
999
|
+
let e = "text";
|
|
1000
|
+
if ("string" === typeof a) {
|
|
1001
|
+
let g = "";
|
|
1002
|
+
if (a.includes("?")) {
|
|
1003
|
+
const [h, f] = a.split("?");
|
|
1004
|
+
a = h;
|
|
1005
|
+
g = f
|
|
1006
|
+
}
|
|
1007
|
+
"function" === typeof b ? (c = d, d = b, b = g) : "object" === typeof b && null !== b ? b = {
|
|
1008
|
+
...b,
|
|
1009
|
+
...$.parseQueryString(g)
|
|
1010
|
+
} : "string" !== typeof b && b || (b = b ? b + "&" + g : g);
|
|
1011
|
+
b = {
|
|
1012
|
+
url: a,
|
|
1013
|
+
method: "POST",
|
|
1014
|
+
data: b,
|
|
1015
|
+
success: d,
|
|
1016
|
+
error: c,
|
|
1017
|
+
dataType: e
|
|
1018
|
+
}
|
|
1019
|
+
} else b = a, e = b.dataType || "text";
|
|
1020
|
+
b.dataType = e;
|
|
1021
|
+
"json" === e && (b.contentType = "application/json");
|
|
1022
|
+
return $.ajax(b)
|
|
1023
|
+
};
|
|
1024
|
+
$.parseQueryString = function(a) {
|
|
1025
|
+
return a ? a.split("&").reduce((b, d) => {
|
|
1026
|
+
const [c, e] = d.split("=");
|
|
1027
|
+
c && (b[decodeURIComponent(c)] = e ? decodeURIComponent(e) : "");
|
|
1028
|
+
return b
|
|
1029
|
+
}, {}) : {}
|
|
1030
|
+
};
|
|
1031
|
+
$.getJSON = function(a, b, d) {
|
|
1032
|
+
return $.ajax({
|
|
1033
|
+
url: a,
|
|
1034
|
+
data: b,
|
|
1035
|
+
dataType: "json",
|
|
1036
|
+
success: d,
|
|
1037
|
+
method: "GET"
|
|
1038
|
+
})
|
|
1039
|
+
};
|
|
1040
|
+
$.get = function() {
|
|
1041
|
+
if (0 === arguments.length || "number" === typeof arguments[0]) {
|
|
1042
|
+
if (this.elements) return 0 === arguments.length ? this.elements : this.elements[arguments[0]]
|
|
1043
|
+
} else {
|
|
1044
|
+
if ("string" === typeof arguments[0]) {
|
|
1045
|
+
var a = arguments[0];
|
|
1046
|
+
if (a.includes("?")) {
|
|
1047
|
+
var b = a.split("?");
|
|
1048
|
+
a = b[0];
|
|
1049
|
+
b = b[1]
|
|
1050
|
+
}
|
|
1051
|
+
if ("function" === typeof arguments[1]) {
|
|
1052
|
+
var d = arguments[1];
|
|
1053
|
+
var c = arguments[2]
|
|
1054
|
+
} else "object" === typeof arguments[1] && null !== arguments[1] && (b = arguments[1], d = arguments[2], c = arguments[3])
|
|
1055
|
+
} else if ("object" === typeof arguments[0]) {
|
|
1056
|
+
var e = arguments[0];
|
|
1057
|
+
a = e.url;
|
|
1058
|
+
b = e.data;
|
|
1059
|
+
d = e.success;
|
|
1060
|
+
c = e.dataType;
|
|
1061
|
+
var g = e.error;
|
|
1062
|
+
e = e.jsonpCallback
|
|
1063
|
+
}
|
|
1064
|
+
return "function" === typeof $.ajax ? (a = {
|
|
1065
|
+
url: a,
|
|
1066
|
+
method: "GET",
|
|
1067
|
+
data: b,
|
|
1068
|
+
dataType: c,
|
|
1069
|
+
success: d,
|
|
1070
|
+
error: g
|
|
1071
|
+
}, "jsonp" === c && e ? a.jsonpCallback = e : "json" === c && (a.contentType = "application/json"), $.ajax(a)) : null
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
$.gets = $.get;
|
|
1075
|
+
$.fn.load = function(a, b, d) {
|
|
1076
|
+
if ("string" !== typeof a) return this.on("load", a);
|
|
1077
|
+
var c = null,
|
|
1078
|
+
e = a;
|
|
1079
|
+
0 < a.indexOf(" ") && (a = a.split(" "), 2 <= a.length && (e = a[0], c = a.slice(1).join(" ")));
|
|
1080
|
+
var g = this;
|
|
1081
|
+
$.ajax({
|
|
1082
|
+
url: e,
|
|
1083
|
+
data: b,
|
|
1084
|
+
success: function(h) {
|
|
1085
|
+
var f = h;
|
|
1086
|
+
if (c && "string" === typeof h) try {
|
|
1087
|
+
var l = (new DOMParser).parseFromString(h, "text/html").querySelector(c);
|
|
1088
|
+
l && (f = l.innerHTML)
|
|
1089
|
+
} catch (k) {}
|
|
1090
|
+
g.each(function() {
|
|
1091
|
+
this.innerHTML = f
|
|
1092
|
+
});
|
|
1093
|
+
d && "function" === typeof d && d.call(g, f, "success", null)
|
|
1094
|
+
},
|
|
1095
|
+
error: function(h, f, l) {
|
|
1096
|
+
d && "function" === typeof d && d.call(g,
|
|
1097
|
+
null, f, l)
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
return this
|
|
1101
|
+
};
|
|
1102
|
+
$.fn.unload = function(a) {
|
|
1103
|
+
if ("function" === typeof a) {
|
|
1104
|
+
var b = function(d) {
|
|
1105
|
+
try {
|
|
1106
|
+
a.call(this, d)
|
|
1107
|
+
} catch (c) {}
|
|
1108
|
+
};
|
|
1109
|
+
window.addEventListener ? window.addEventListener("beforeunload", b) : window.attachEvent && window.attachEvent("onbeforeunload", b);
|
|
1110
|
+
this.removeUnload = function() {
|
|
1111
|
+
window.removeEventListener ? window.removeEventListener("beforeunload", b) : window.detachEvent && window.detachEvent("onbeforeunload", b)
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
return this
|
|
1115
|
+
};
|
|
1116
|
+
$.load = function(a, b, d) {
|
|
1117
|
+
return $(document.body).load(a, b, d)
|
|
1118
|
+
};
|
|
1119
|
+
$.unload = function(a) {
|
|
1120
|
+
return $(window).on("beforeunload", a)
|
|
1121
|
+
};
|
|
1122
|
+
$.fn.ajax = function(a, b) {
|
|
1123
|
+
return $.ajax.call(this, a, b)
|
|
1124
|
+
};
|
|
1125
|
+
$.fn.post = function(a, b, d, c) {
|
|
1126
|
+
return $.post.apply(this, arguments)
|
|
1127
|
+
};
|
|
1128
|
+
$.fn.getJSON = function(a, b, d) {
|
|
1129
|
+
return $.getJSON.apply(this, arguments)
|
|
1130
|
+
};
|
|
1131
|
+
$.fn.get = function() {
|
|
1132
|
+
return $.get.apply(this, arguments)
|
|
1133
|
+
};
|
|
1134
|
+
$.fn.gets = $.fn.get;
|
|
1135
|
+
$.ajaxDebug = function(a) {
|
|
1136
|
+
if (void 0 === a) return window.AJAX_DEBUG || AJAX_CONFIG.DEBUG.ENABLED || !1;
|
|
1137
|
+
window.AJAX_DEBUG = !!a;
|
|
1138
|
+
AJAX_CONFIG.DEBUG.ENABLED = !!a;
|
|
1139
|
+
"undefined" !== typeof localStorage && (a ? localStorage.setItem("ajax_debug", "true") : localStorage.removeItem("ajax_debug"));
|
|
1140
|
+
return a
|
|
1141
|
+
};
|
|
1142
|
+
$.detectWebView = function() {
|
|
1143
|
+
return 0 < detectAvailableBridges().length ? "webview" : "web"
|
|
1144
|
+
};
|
|
1145
|
+
$.checkWebViewBridge = function() {
|
|
1146
|
+
return $.getAllBridgesStatus()
|
|
1147
|
+
};
|
|
1148
|
+
$.ajaxConstants = function(a, b) {
|
|
1149
|
+
if (0 === arguments.length) return {
|
|
1150
|
+
...AJAX_CONFIG
|
|
1151
|
+
};
|
|
1152
|
+
if (1 === arguments.length) return AJAX_CONFIG[a];
|
|
1153
|
+
if (2 === arguments.length) return AJAX_CONFIG.hasOwnProperty(a) ? AJAX_CONFIG[a] = b : null
|
|
1154
|
+
};
|
|
1155
|
+
$.getBridgePriority = function() {
|
|
1156
|
+
return {
|
|
1157
|
+
...bridgePriority
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
$.ajaxStatus = function() {
|
|
1161
|
+
const a = detectEnvironmentAjax("http://test.com");
|
|
1162
|
+
return {
|
|
1163
|
+
version: AJAX_CONFIG.VERSION,
|
|
1164
|
+
environment: a,
|
|
1165
|
+
bridges: detectAvailableBridges(),
|
|
1166
|
+
customBridges: $.getCustomBridges(),
|
|
1167
|
+
config: AJAX_CONFIG,
|
|
1168
|
+
debugMode: $.ajaxDebug(),
|
|
1169
|
+
fileUrlHandling: AJAX_CONFIG.FILE_URL_HANDLING
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
$.ajaxConfig = function(a, b) {
|
|
1173
|
+
if (0 === arguments.length) return AJAX_CONFIG;
|
|
1174
|
+
if (1 === arguments.length) {
|
|
1175
|
+
var d = a.split("."),
|
|
1176
|
+
c = AJAX_CONFIG;
|
|
1177
|
+
for (var e of d) {
|
|
1178
|
+
if (void 0 === c[e]) return;
|
|
1179
|
+
c = c[e]
|
|
1180
|
+
}
|
|
1181
|
+
return c
|
|
1182
|
+
}
|
|
1183
|
+
if (2 === arguments.length) {
|
|
1184
|
+
d = a.split(".");
|
|
1185
|
+
c = AJAX_CONFIG;
|
|
1186
|
+
for (e = 0; e < d.length - 1; e++) c[d[e]] || (c[d[e]] = {}), c = c[d[e]];
|
|
1187
|
+
e = c[d[d.length - 1]];
|
|
1188
|
+
c[d[d.length - 1]] = b;
|
|
1189
|
+
return e
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
$.testFileUrl = function(a) {
|
|
1193
|
+
return $.ajax({
|
|
1194
|
+
url: a || "./test.txt",
|
|
1195
|
+
method: "GET",
|
|
1196
|
+
success: function(b) {
|
|
1197
|
+
console.log("File URL test successful", {
|
|
1198
|
+
dataLength: b ? b.length : 0
|
|
1199
|
+
})
|
|
1200
|
+
},
|
|
1201
|
+
error: function(b) {
|
|
1202
|
+
console.error("File URL test failed", b)
|
|
1203
|
+
}
|
|
1204
|
+
})
|
|
1205
|
+
};
|
|
1206
|
+
"file:" === location.protocol && (AJAX_CONFIG.FILE_URL_HANDLING.FORCE_WEBVIEW_BRIDGE = !0, AJAX_CONFIG.DEBUG.FILE_URL_VERBOSE = !0);
|
|
1207
|
+
const domquery_urlToDivMap = {},
|
|
1208
|
+
domqueryTranslationInterface = {
|
|
1209
|
+
urlToDivMap: domquery_urlToDivMap,
|
|
1210
|
+
updateTranslationDivFromJSON: domquery_updateTranslationDivFromJSON
|
|
1211
|
+
};
|
|
1212
|
+
window.domqueryTranslationInterface = domqueryTranslationInterface;
|
|
1213
|
+
(function() {
|
|
1214
|
+
"loading" === document.readyState ? document.addEventListener("DOMContentLoaded", function() {
|
|
1215
|
+
domquery_cleanupExpiredScripts()
|
|
1216
|
+
}) : domquery_cleanupExpiredScripts();
|
|
1217
|
+
setInterval(function() {
|
|
1218
|
+
domquery_cleanupExpiredScripts()
|
|
1219
|
+
}, 6E5)
|
|
1220
|
+
})();
|