mirror of
https://github.com/anyproto/anytype-ts.git
synced 2025-06-09 17:45:02 +09:00
127 lines
No EOL
2.5 KiB
HTML
127 lines
No EOL
2.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<style type="text/css">
|
|
* { margin: 0px; padding: 0px; }
|
|
|
|
html, body, #root { height: 100%; }
|
|
|
|
body { background-color: #fff; }
|
|
body.dark { background-color: #171717; }
|
|
|
|
body.align1 { text-align: center; }
|
|
body.align2 { text-align: right; }
|
|
|
|
body:not(.isTwitter) {
|
|
iframe { width: 100% !important; height: 100% !important; }
|
|
}
|
|
|
|
.twitter-tweet { margin: 0px !important; display: inline-flex !important; }
|
|
|
|
body.align1 .twitter-tweet { justify-content: center; }
|
|
body.align2 .twitter-tweet { justify-content: flex-end; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="root"></div>
|
|
<script type="text/javascript">
|
|
let cachedHtml = '';
|
|
let scrollHeight = 0;
|
|
|
|
const param = getParam();
|
|
const body = document.body;
|
|
const root = document.getElementById('root');
|
|
const allowedOrigins = [
|
|
'//localhost:',
|
|
'file://',
|
|
];
|
|
|
|
body.className = '';
|
|
|
|
if (param.theme) {
|
|
body.classList.add(param.theme);
|
|
};
|
|
|
|
window.addEventListener('message', e => {
|
|
if (!allowedOrigins.some(it => e.origin.match(it))) {
|
|
return;
|
|
};
|
|
|
|
const { html, js, libs, className, allowResize, align } = e.data;
|
|
|
|
if (className) {
|
|
body.classList.add(className);
|
|
};
|
|
|
|
body.classList.add(`align${align}`);
|
|
|
|
loadLibs(libs, () => {
|
|
if (cachedHtml !== html) {
|
|
root.innerHTML = html;
|
|
cachedHtml = html;
|
|
};
|
|
|
|
if (js) {
|
|
try {
|
|
eval(js);
|
|
} catch (e) {
|
|
console.error(e);
|
|
};
|
|
};
|
|
|
|
resize();
|
|
if (allowResize) {
|
|
setInterval(resize, 500);
|
|
};
|
|
});
|
|
});
|
|
|
|
window.addEventListener('resize', resize);
|
|
|
|
window.onerror = function (message, url, lineNumber) {
|
|
return true;
|
|
};
|
|
|
|
function resize () {
|
|
window.parent.postMessage({ height: document.documentElement.scrollHeight }, '*');
|
|
};
|
|
|
|
function loadLibs (list, callBack) {
|
|
if (!list.length) {
|
|
if (callBack) {
|
|
callBack();
|
|
};
|
|
return;
|
|
};
|
|
|
|
const src = list.shift();
|
|
const script = document.createElement('script');
|
|
|
|
document.body.appendChild(script);
|
|
|
|
script.onload = function (e) {
|
|
if (list.length) {
|
|
loadLibs(list, callBack);
|
|
} else
|
|
if (callBack) {
|
|
callBack();
|
|
};
|
|
};
|
|
|
|
script.type = 'text/javascript';
|
|
script.src = src;
|
|
};
|
|
|
|
function getParam () {
|
|
const a = location.search.replace(/^\?/, '').split('&');
|
|
const param = {};
|
|
|
|
a.forEach((s) => {
|
|
const kv = s.split('=');
|
|
param[kv[0]] = kv[1];
|
|
});
|
|
return param;
|
|
};
|
|
</script>
|
|
</body>
|
|
</html> |