-
Notifications
You must be signed in to change notification settings - Fork 0
/
btn.js
46 lines (39 loc) · 1.63 KB
/
btn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
LAME_CDN = `https://lame.netlify.com/`;
LAME_CURRENT_URL = window.location.href;
LAME_SUPPORTED_SITES = [
/* Self */
{rx: /lame\.netlify\.app/, scriptSrc: `${LAME_CDN}project-page.js`},
/* Flitto */
{rx: /https:\/\/www\.flitto\.com/, scriptSrc: `${LAME_CDN}flitto.js`},
/* Vitamin */
{rx: /a\.flit\.to:4435\/admin#\/admin\/req_tr/, scriptSrc: `${LAME_CDN}crowd-monitoring.js`},
{rx: /a3\.flit\.to\/#\/arcade\/arcade-objection/, scriptSrc: `${LAME_CDN}arcade-objection.js`},
{rx: /a3\.flit\.to\/#\/arcade\/arcade-user-history/, scriptSrc: `${LAME_CDN}arcade-history.js`},
{rx: /a3\.flit\.to\/#\/pro-tr\/pro-applicant\/\d/, scriptSrc: `${LAME_CDN}pro-applicant.js`},
{rx: /a3\.flit\.to\/#\/menu-tr/, scriptSrc: `${LAME_CDN}place-export.js`},
/* Others */
{rx: /api-demo\.flit\.to/, scriptSrc: `${LAME_CDN}extend-simi-sites.js`},
{rx: /translators\.to/, scriptSrc: `${LAME_CDN}extend-simi-sites.js`},
{rx: /desertfox\.io.+post/, scriptSrc: `${LAME_CDN}df-multirequest.js`},
];
matchedScript = '';
for (let {rx, scriptSrc} of LAME_SUPPORTED_SITES) {
if (rx.test(LAME_CURRENT_URL)) { matchedScript = scriptSrc }
}
if (matchedScript) {
if (!document.head.querySelectorAll(`[src="${matchedScript}"]`).length) {
injectRemoteScript(matchedScript).then(()=> { lameify() })
}
else {
lameify()
}
}
function injectRemoteScript(src) {
return new Promise((resolve, reject) => {
let script = document.createElement('script');
script.src = src;
script.onload = () => resolve(/* script */);
script.onerror = () => reject(new Error(`Script load error for ${src}`));
document.head.append(script);
});
}