unify autoresize code

master
Aevann 2024-08-15 20:35:49 +03:00
parent 2167f283e2
commit f1e8f430fd
5 changed files with 19 additions and 24 deletions

View File

@ -1,4 +0,0 @@
addEventListener('message', function (e) {
if (e.origin == "https://www.teamblind.com" && e.data.height)
document.getElementById('external-embed').height = e.data.height;
});

View File

@ -1,8 +0,0 @@
addEventListener('message', function (e) {
if (e.origin == "https://www.instagram.com") {
const height = JSON.parse(e.data).details.height
if (height)
document.getElementById('external-embed').height = height;
}
});

View File

@ -1,3 +1,18 @@
const autoresizable = document.querySelector('#external-embed.autoresizable')
if (autoresizable) {
addEventListener('message', function (e) {
if (e.origin == "https://www.teamblind.com" && e.data.height)
autoresizable.height = e.data.height;
if (e.origin == "https://www.instagram.com") {
const height = JSON.parse(e.data).details.height
if (height)
autoresizable.height = height;
}
if (e.origin.endsWith('.substack.com') && e.data.iframeHeight)
autoresizable.height = e.data.iframeHeight;
});
}
function highlight_unread(localstoragevar) {
const comments = JSON.parse(localStorage.getItem(localstoragevar)) || {}

View File

@ -1,4 +0,0 @@
addEventListener('message', function (e) {
if (e.origin.endsWith('.substack.com') && e.data.iframeHeight)
document.getElementById('external-embed').height = e.data.iframeHeight;
});

View File

@ -153,9 +153,8 @@
{% elif p.url.startswith('https://www.teamblind.com/') %}
{% set id = p.url.split('-')[-1] %}
{% if id %}
<iframe id="external-embed" scrolling="no" src="https://www.teamblind.com/embed/{{id}}" height="500" width="500" style="max-width:100%"></iframe>
<iframe id="external-embed" scrolling="no" class="autoresizable" src="https://www.teamblind.com/embed/{{id}}" height="500" width="500" style="max-width:100%"></iframe>
{% endif %}
<script defer src="{{'js/blind_embed.js' | asset}}"></script>
{% elif p.url.startswith('https://instagram.com/') %}
{% set path = p.url.split('https://instagram.com/')[1].rstrip('/') %}
{% if '/' in path %}
@ -163,16 +162,13 @@
{% else %}
{% set path = path + '/embed' %}
{% endif %}
<iframe id="external-embed" scrolling="no" src="https://www.instagram.com/{{path}}" style="width:calc(100% - 2px);min-width:326px;max-width:540px"></iframe>
<script defer src="{{'js/instagram_embed.js' | asset}}"></script>
<iframe id="external-embed" scrolling="no" class="autoresizable" src="https://www.instagram.com/{{path}}" style="width:calc(100% - 2px);min-width:326px;max-width:540px"></iframe>
{% elif p.domain.endswith('substack.com') %}
{% if 'substack.com/p/' in p.url and p.url.count('/') == 4 %}
<iframe id="external-embed" scrolling="no" src="{{p.url.replace('substack.com/p/', 'substack.com/embed/p/')}}?origin={{SITE_FULL}}" height="500" width="500" style="max-width:100%"></iframe>
<script defer src="{{'js/substack_embed.js' | asset}}"></script>
<iframe id="external-embed" scrolling="no" class="autoresizable" src="{{p.url.replace('substack.com/p/', 'substack.com/embed/p/')}}?origin={{SITE_FULL}}" height="500" width="500" style="max-width:100%"></iframe>
{% elif '/note/c-' in p.url %}
{% set id = p.url.split('/note/c-')[-1] %}
<iframe id="external-embed" scrolling="no" src="https://substack.com/embed/c/{{id}}?origin={{SITE_FULL}}" height="500" width="500" style="max-width:100%"></iframe>
<script defer src="{{'js/substack_embed.js' | asset}}"></script>
<iframe id="external-embed" scrolling="no" class="autoresizable" src="https://substack.com/embed/c/{{id}}?origin={{SITE_FULL}}" height="500" width="500" style="max-width:100%"></iframe>
{% endif %}
{% endif %}
{% endif %}