2022-03-11 19:58:12 +08:00
|
|
|
(doc => {
|
2020-08-10 16:40:25 +08:00
|
|
|
|
|
|
|
const
|
2023-01-19 23:46:39 +08:00
|
|
|
qUri = path => doc.location.pathname.replace(/\/+$/,'') + '/?/' + path,
|
2021-07-26 21:06:28 +08:00
|
|
|
eId = id => doc.getElementById('rl-'+id),
|
|
|
|
app = eId('app'),
|
2021-02-17 03:12:23 +08:00
|
|
|
admin = app && '1' == app.dataset.admin,
|
2022-03-11 19:58:12 +08:00
|
|
|
layout = doc.cookie.match(/(^|;) ?rllayout=([^;]+)/) || '',
|
2020-09-03 22:34:23 +08:00
|
|
|
|
2022-11-07 06:10:34 +08:00
|
|
|
showError = msg => {
|
|
|
|
let div = eId('loading-error');
|
2023-01-30 16:10:49 +08:00
|
|
|
div.append(msg);
|
2022-11-07 06:10:34 +08:00
|
|
|
eId('loading').hidden = true;
|
|
|
|
div.hidden = false;
|
|
|
|
},
|
|
|
|
|
2020-09-03 22:34:23 +08:00
|
|
|
loadScript = src => {
|
|
|
|
if (!src) {
|
|
|
|
throw new Error('src should not be empty.');
|
|
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const script = doc.createElement('script');
|
2021-04-29 04:59:42 +08:00
|
|
|
script.onload = () => resolve();
|
2022-11-12 00:50:18 +08:00
|
|
|
script.onerror = () => reject('Failed loading ' + src);
|
2020-09-03 22:34:23 +08:00
|
|
|
script.src = src;
|
2022-10-02 21:19:23 +08:00
|
|
|
// script.async = true;
|
2020-09-03 22:34:23 +08:00
|
|
|
doc.head.append(script);
|
|
|
|
});
|
2022-02-08 21:15:22 +08:00
|
|
|
};
|
2020-08-10 16:40:25 +08:00
|
|
|
|
2022-11-28 17:39:28 +08:00
|
|
|
try {
|
2022-12-27 17:24:16 +08:00
|
|
|
let smctoken = doc.cookie.match(/(^|;) ?smctoken=([^;]+)/);
|
|
|
|
smctoken = smctoken ? smctoken[2] : localStorage.getItem('smctoken');
|
2022-11-28 17:39:28 +08:00
|
|
|
if (!smctoken) {
|
|
|
|
let data = new Uint8Array(16);
|
|
|
|
crypto.getRandomValues(data);
|
2022-12-28 03:57:11 +08:00
|
|
|
smctoken = encodeURIComponent(btoa(String.fromCharCode(...data)));
|
2022-11-28 17:39:28 +08:00
|
|
|
}
|
2022-12-27 17:24:16 +08:00
|
|
|
localStorage.setItem('smctoken', smctoken);
|
2023-02-02 19:55:06 +08:00
|
|
|
// doc.cookie = `smctoken=${smctoken};path=${doc.location.pathname};samesite=strict;secure";
|
|
|
|
// doc.cookie = 'smctoken='+smctoken+";path=/;samesite=lax";
|
|
|
|
doc.cookie = 'smctoken='+smctoken+";path=/;samesite=strict";
|
2022-11-28 17:39:28 +08:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
|
2022-03-11 19:58:12 +08:00
|
|
|
let RL_APP_DATA = {};
|
2021-02-16 21:40:11 +08:00
|
|
|
|
2022-02-28 22:10:04 +08:00
|
|
|
doc.documentElement.classList.toggle('rl-mobile', 'mobile' === layout[2] || (!layout && 1000 > innerWidth));
|
2021-04-29 04:59:42 +08:00
|
|
|
|
2022-03-11 19:58:12 +08:00
|
|
|
window.rl = {
|
2021-02-17 03:12:23 +08:00
|
|
|
adminArea: () => admin,
|
2022-04-25 15:57:32 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
settings: {
|
2021-09-23 21:30:08 +08:00
|
|
|
get: name => RL_APP_DATA[name],
|
2020-09-23 17:20:00 +08:00
|
|
|
set: (name, value) => RL_APP_DATA[name] = value,
|
2022-04-25 15:57:32 +08:00
|
|
|
app: name => RL_APP_DATA.System[name]
|
2020-09-23 17:20:00 +08:00
|
|
|
},
|
2022-04-25 15:57:32 +08:00
|
|
|
|
2022-11-14 16:15:25 +08:00
|
|
|
setTitle: title =>
|
2022-11-12 00:50:18 +08:00
|
|
|
doc.title = (title || '') + (RL_APP_DATA.Title ? (title ? ' - ' : '') + RL_APP_DATA.Title : ''),
|
2016-05-06 23:14:40 +08:00
|
|
|
|
2020-09-23 17:20:00 +08:00
|
|
|
initData: appData => {
|
|
|
|
RL_APP_DATA = appData;
|
2022-03-11 19:58:12 +08:00
|
|
|
const url = appData.StaticLibsJs,
|
2022-11-14 16:15:25 +08:00
|
|
|
cb = () => rl.app.bootstart();
|
2022-03-11 19:58:12 +08:00
|
|
|
loadScript(url)
|
|
|
|
.then(() => loadScript(url.replace('/libs.', `/${admin?'admin':'app'}.`)))
|
2023-01-19 23:46:39 +08:00
|
|
|
.then(() => appData.PluginsLink ? loadScript(qUri(appData.PluginsLink)) : Promise.resolve())
|
2022-04-28 21:12:52 +08:00
|
|
|
.then(() => rl.app
|
2022-04-16 08:38:57 +08:00
|
|
|
? cb()
|
|
|
|
: doc.addEventListener('readystatechange', () => 'complete' == doc.readyState && cb())
|
|
|
|
)
|
2020-09-23 17:20:00 +08:00
|
|
|
.catch(e => {
|
2022-05-01 03:26:57 +08:00
|
|
|
showError(e);
|
2020-08-12 06:25:36 +08:00
|
|
|
throw e;
|
2021-09-23 21:30:08 +08:00
|
|
|
});
|
2021-11-01 18:24:11 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
setData: appData => {
|
|
|
|
RL_APP_DATA = appData;
|
|
|
|
rl.app.refresh();
|
2022-03-10 16:57:27 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
loadScript: loadScript
|
2020-08-12 06:25:36 +08:00
|
|
|
};
|
|
|
|
|
2023-01-30 16:10:49 +08:00
|
|
|
if (!navigator.cookieEnabled) {
|
|
|
|
eId('loading').hidden = true;
|
|
|
|
eId('NoCookie').hidden = false;
|
|
|
|
} else if (![].flat) {
|
|
|
|
eId('loading').hidden = true;
|
|
|
|
eId('BadBrowser').hidden = false;
|
|
|
|
} else {
|
|
|
|
loadScript(qUri(`${admin ? 'Admin' : ''}AppData/0/${Math.random().toString().slice(2)}/`))
|
2022-11-07 06:10:34 +08:00
|
|
|
.catch(e => showError(e));
|
2023-01-30 16:10:49 +08:00
|
|
|
}
|
2020-08-10 16:40:25 +08:00
|
|
|
|
2022-03-11 19:58:12 +08:00
|
|
|
})(document);
|