mirror of
https://github.com/funamitech/mastodon
synced 2024-12-14 22:59:46 +09:00
1b06e4e1b7
Conflicts: - `app/javascript/packs/public.jsx`: In glitch-soc, this file was split across the following files: - `app/javascript/packs/public.jsx` - `app/javascript/core/embed.js` - `app/javascript/core/settings.js` Update all those files accordingly, as well as the related `theme.yml` files.
42 lines
1010 B
TypeScript
42 lines
1010 B
TypeScript
// This file will be loaded on embed pages, regardless of theme.
|
|
|
|
import 'packs/public-path';
|
|
import ready from '../mastodon/ready';
|
|
|
|
interface SetHeightMessage {
|
|
type: 'setHeight';
|
|
id: string;
|
|
height: number;
|
|
}
|
|
|
|
function isSetHeightMessage(data: unknown): data is SetHeightMessage {
|
|
if (
|
|
data &&
|
|
typeof data === 'object' &&
|
|
'type' in data &&
|
|
data.type === 'setHeight'
|
|
)
|
|
return true;
|
|
else return false;
|
|
}
|
|
|
|
window.addEventListener('message', (e) => {
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- typings are not correct, it can be null in very rare cases
|
|
if (!e.data || !isSetHeightMessage(e.data) || !window.parent) return;
|
|
|
|
const data = e.data;
|
|
|
|
ready(() => {
|
|
window.parent.postMessage(
|
|
{
|
|
type: 'setHeight',
|
|
id: data.id,
|
|
height: document.getElementsByTagName('html')[0].scrollHeight,
|
|
},
|
|
'*',
|
|
);
|
|
}).catch((e) => {
|
|
console.error('Error in setHeightMessage postMessage', e);
|
|
});
|
|
});
|