2022-03-11 19:58:12 +08:00
|
|
|
(doc => {
|
2020-08-10 16:40:25 +08:00
|
|
|
|
2022-03-11 19:58:12 +08:00
|
|
|
[].flat || doc.location.replace('./?/BadBrowser');
|
|
|
|
navigator.cookieEnabled || doc.location.replace('./?/NoCookie');
|
2020-08-10 16:40:25 +08:00
|
|
|
|
|
|
|
const
|
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
|
|
|
|
|
|
|
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();
|
2021-08-18 18:23:48 +08:00
|
|
|
script.onerror = () => reject(new Error('Failed loading ' + src));
|
2020-09-03 22:34:23 +08:00
|
|
|
script.src = src;
|
2020-09-23 17:20:00 +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-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,
|
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,
|
2021-09-23 21:30:08 +08:00
|
|
|
app: name => RL_APP_DATA.System[name],
|
2022-02-24 19:22:27 +08:00
|
|
|
capa: name => name && !!(RL_APP_DATA.Capa || {})[name]
|
2020-09-23 17:20:00 +08:00
|
|
|
},
|
2021-09-17 21:09:47 +08:00
|
|
|
setWindowTitle: title =>
|
|
|
|
doc.title = RL_APP_DATA.Title ? (title ? title + ' - ' : '') + RL_APP_DATA.Title : (title ? '' + 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,
|
|
|
|
cb = () => rl.app.bootstart(),
|
|
|
|
div = eId('loading-error'),
|
|
|
|
showError = msg => {
|
|
|
|
div.append(' ' + msg);
|
|
|
|
eId('loading').hidden = true;
|
|
|
|
div.hidden = false;
|
|
|
|
};
|
|
|
|
loadScript(url)
|
|
|
|
.then(() => loadScript(url.replace('/libs.', `/${admin?'admin':'app'}.`)))
|
2020-09-23 17:20:00 +08:00
|
|
|
.then(() => appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve())
|
2021-09-23 21:30:08 +08:00
|
|
|
.then(() => ('loading' !== doc.readyState) ? cb() : doc.addEventListener('DOMContentLoaded', cb))
|
2020-09-23 17:20:00 +08:00
|
|
|
.catch(e => {
|
2021-08-18 18:23:48 +08:00
|
|
|
showError(e.message);
|
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
|
|
|
};
|
|
|
|
|
2021-12-08 18:35:41 +08:00
|
|
|
loadScript(`./?/${admin ? 'Admin' : ''}AppData/0/${Math.random().toString().slice(2)}/`)
|
2021-08-18 21:36:33 +08:00
|
|
|
.then(() => 0);
|
2020-08-10 16:40:25 +08:00
|
|
|
|
2022-03-11 19:58:12 +08:00
|
|
|
})(document);
|