revert 726a004400 for the following reasons:

- the new embeds are actually much slower on mobile when u first load the page
- it broke embeds for a lot of ppl for some reason
- ppl apparently delete their tweets much more frequently than i thought, and ghostarchive.org obv doesnt run on comments or chat messages
- dont rly need lazyloading, the old embeds didnt hang up anything, ran after load and were never noticable or cpu-heavy
- the tracking is the same tbh, not much i can do about that
- who cares about retroactivity

despair, agony, etc
master
Aevann 2024-08-17 19:10:59 +03:00
parent 229a80266d
commit 1e6f851e6e
17 changed files with 91 additions and 70 deletions

View File

@ -7735,10 +7735,10 @@ img[src$="/e/speechbubble.webp"] {
margin-bottom: 10px;
}
.twitter-embed, .reddit-embed {
.reddit-embed {
border: none;
display: inline !important;
width: min(100%, 552px);
width: 552px;
vertical-align: middle;
}

View File

@ -160,7 +160,8 @@ socket.on('speak', function(json) {
if (scrolled_down_var)
box.scrollTo(0, box.scrollHeight)
embed_twitter_reddit()
embed_twitter()
embed_reddit()
})
socket.on('error', function(message) {

View File

@ -197,7 +197,8 @@ function post_reply(id) {
remove_dialog();
restore_reply_buttons(`c_${id}`)
embed_twitter_reddit()
embed_twitter()
embed_reddit()
} else {
showToast(false, getMessageFromJsonData(false, data));
}
@ -266,7 +267,8 @@ function comment_edit(id) {
remove_dialog();
embed_twitter_reddit()
embed_twitter()
embed_reddit()
}
else {
showToast(false, getMessageFromJsonData(false, data));
@ -356,7 +358,8 @@ function post_comment(fullname, hide) {
viewbtn.dataset.ids = viewbtn.dataset.ids.slice(0, -1) + `, ${data['id']}]`
}
embed_twitter_reddit()
embed_twitter()
embed_reddit()
}
else {
showToast(false, getMessageFromJsonData(false, data));

View File

@ -1,51 +0,0 @@
function embed_twitter_reddit() {
if (navigator.doNotTrack == "1") return
for (const a of document.querySelectorAll('a[href^="https://x.com/"][href*="/status/"]')) {
if (a.innerHTML && a.innerHTML !== a.href) continue
if (["STRONG", "LI", "BLOCKQUOTE"].includes(a.parentElement.tagName)) continue
const id = a.href.split('/status/')[1].split('?')[0]
let iframe_src = `https://platform.twitter.com/embed/Tweet.html?dnt=true&id=${id}`
if (document.body.dataset.dark)
iframe_src += "&theme=dark"
a.innerHTML = `<iframe class="twitter-embed" credentialless="true" sandbox="allow-scripts allow-same-origin allow-popups" allowfullscreen="true" loading="lazy" height="500" src="${iframe_src}" scrolling="no"></iframe>`
}
for (const a of document.querySelectorAll('a[href^="https://old.reddit.com/r/"]:not(a[href$="/new"])')) {
if (a.innerHTML && a.innerHTML !== a.href) continue
if (["STRONG", "LI", "BLOCKQUOTE"].includes(a.parentElement.tagName)) continue
let iframe_src = a.href.replace('https://old.reddit.com/', 'https://embed.reddit.com/')
iframe_src = iframe_src.split('?')[0]
iframe_src += "?context=1&showtitle=true"
if (document.body.dataset.dark)
iframe_src += "&theme=dark"
a.innerHTML = `<iframe class="reddit-embed" credentialless="true" sandbox="allow-scripts allow-popups" loading="lazy" height="240" src="${iframe_src}" scrolling="no"></iframe>`
}
}
embed_twitter_reddit()
addEventListener("message", function(e) {
if (e.origin == "https://platform.twitter.com") {
const height = e.data["twttr.embed"]["params"][0]["height"]
if (height) {
for (const iframe of document.getElementsByClassName("twitter-embed")) {
if (e.source === iframe.contentWindow)
iframe.height = height
}
}
}
if (typeof e.data == "string" && e.data) {
const data = JSON.parse(e.data)
const height = data.data
if (data && "type" in data && data.type == "resize.embed")
for (const iframe of document.getElementsByClassName("reddit-embed")) {
if (e.source === iframe.contentWindow)
iframe.height = height
}
}
})

View File

@ -17,7 +17,8 @@ function more_comments(cid, sort) {
highlight_unread("old-comment-counts")
embed_twitter_reddit()
embed_twitter()
embed_reddit()
}
btn.disabled = false;
}

View File

@ -0,0 +1,28 @@
function embed_reddit() {
if (navigator.doNotTrack == "1") return
for (const a of document.querySelectorAll('a[href^="https://old.reddit.com/r/"]:not(a[href$="/new"])')) {
if (a.innerHTML && a.innerHTML !== a.href) continue
if (a.parentElement.tagName == "STRONG") continue
let iframe_src = a.href.replace('https://old.reddit.com/', 'https://embed.reddit.com/')
iframe_src = iframe_src.split('?')[0]
iframe_src += "?context=1&showtitle=true"
if (document.body.dataset.dark)
iframe_src += "&theme=dark"
a.innerHTML = `<iframe class="reddit-embed" credentialless="true" loading="lazy" height="240" src="${iframe_src}" scrolling="no" sandbox="allow-scripts allow-popups"></iframe>`
}
}
embed_reddit()
addEventListener("message", function(e) {
if (typeof e.data == "string" && e.data) {
const data = JSON.parse(e.data)
let height = data.data
if (data && "type" in data && data.type == "resize.embed")
for (const iframe of document.getElementsByClassName("reddit-embed")) {
if (e.source === iframe.contentWindow)
iframe.height = height
}
}
})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,8 @@ function view_more(t, pid, sort, offset) {
highlight_unread("old-comment-counts")
embed_twitter_reddit()
embed_twitter()
embed_reddit()
}
btn.disabled = false;
}

View File

@ -582,6 +582,17 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=False, count_emojis
del link["href"]
continue
if not snappy and link.string == link["href"]:
if link["href"].startswith('https://x.com/') and '/status/' in link["href"]:
try:
embed = requests.get("https://publish.x.com/oembed", params={"url":link["href"], "omit_script":"t", "dnt":"t"}, headers=HEADERS, timeout=5).json()["html"]
except:
pass
else:
embed = embed.replace('<a href', '<a rel="nofollow noopener" href')
embed = BeautifulSoup(embed, 'lxml')
link.replaceWith(embed)
sanitized = str(soup).replace('<html><body>','').replace('</body></html>','').replace('/>','>')
captured = []

View File

@ -541,7 +541,12 @@ def submit_post(v, hole=None):
if combined.startswith(x.domain):
stop(400, f'Remove the banned link "{x.domain}" and try again!\nReason for link ban: "{x.reason}"')
if url.startswith('https://youtube.com/watch?'):
if domain == "x.com" and '/status/' in url:
try:
embed = requests.get("https://publish.x.com/oembed", params={"url":url, "omit_script":"t", "dnt":"t"}, headers=HEADERS, timeout=5).json()["html"]
embed = embed.replace('<a href', '<a rel="nofollow noopener" href')
except: pass
elif url.startswith('https://youtube.com/watch?'):
embed = handle_youtube_links(url)
elif SITE in domain and "/post/" in url and "context" not in url and url.count('/') < 6:
id = url.split("/post/")[1]

View File

@ -120,5 +120,6 @@
{% if not session.get("GLOBAL") %}
<script defer src="{{'js/chat.js' | asset}}"></script>
{% endif %}
<script defer src="{{'js/embed_twitter_reddit.js' | asset}}"></script>
<script defer src="{{'js/vendor/twitter.js' | asset}}"></script>
<script defer src="{{'js/reddit_embed.js' | asset}}"></script>
{% endblock %}

View File

@ -851,6 +851,7 @@
</div>
{% endif %}
<script defer src="{{'js/embed_twitter_reddit.js' | asset}}"></script>
<script defer src="{{'js/vendor/twitter.js' | asset}}"></script>
<script defer src="{{'js/reddit_embed.js' | asset}}"></script>
</body>

View File

@ -139,7 +139,7 @@
{% endif %}
{% endif %}
{% if IS_MUSICAL_EVENT() and not (SITE_NAME == 'WPD' and not v) and (not v or v.event_music) and not (hole and hole.name == 'music') and not (u and u.song) and not (IS_HOMOWEEN() and p and p.award_count("haunt", v)) %}
{% if IS_MUSICAL_EVENT() and not (SITE_NAME == 'WPD' and not v) and (not v or v.event_music) and not (hole and hole.name == 'music') and not (u and u.song) and not (IS_HOMOWEEN() and p and p.award_count("haunt", v)) and not (p and p.embed and p.domain == 'x.com') %}
{% set path = "assets/events/" ~ IS_EVENT() ~ "/music" %}
{% set song = SITE_FULL ~ "/" ~ path ~ "/" ~ listdir('files/'~path)|seeded_random(id) ~ '?x=45' %}
<audio id="event-song" hidden preload="none" src="{{song}}" loop></audio>

View File

@ -132,5 +132,6 @@
{% if not session.get("GLOBAL") %}
<script defer src="{{'js/chat.js' | asset}}"></script>
{% endif %}
<script defer src="{{'js/embed_twitter_reddit.js' | asset}}"></script>
<script defer src="{{'js/vendor/twitter.js' | asset}}"></script>
<script defer src="{{'js/reddit_embed.js' | asset}}"></script>
{% endblock %}

View File

@ -122,11 +122,13 @@
{% endif %}
{% if p.embed %}
{% if p.domain in ['youtu.be','youtube.com'] and p.embed.startswith('<lite-youtube') %}
{% if p.domain == "x.com" %}
{{p.embed | safe}}
{% elif p.domain in ['youtu.be','youtube.com'] and p.embed.startswith('<lite-youtube') %}
<p class="resizable yt" style="width:100%">
{{p.embed | safe}}
</p>
{% elif 'twitter-tweet' not in p.embed %}
{% else %}
<div id="crosspost-embed" class="mb-3" style="border: 1px solid var(--primary)">
<div class="row no-gutters">
<div id="frontpage" class="col-12 pt-0">
@ -140,7 +142,7 @@
{% endif %}
{% if p.url %}
{% if (p.url.startswith('https://old.reddit.com/r/') and not p.url.endswith('/new/')) or (p.url.startswith('https://x.com/') and '/status/' in p.url) %}
{% if p.url.startswith('https://old.reddit.com/r/') and not p.url.endswith('/new/') %}
<a rel="nofollow noopener" href="{{p.url}}"></a>
<pre></pre>
{% elif p.url.startswith('https://tiktok.com/@') %}

View File

@ -106,7 +106,7 @@
</h5>
<div class="post-actions d-mob-none">
<ul class="list-inline text-right d-flex">
{% if p.realbody(v) %}
{% if p.realbody(v) or (p.embed and p.domain == "x.com") %}
<button type="button" class="list-inline-item ml-2" data-nonce="{{g.nonce}}" data-onclick="expandText('{{p.id}}')"><i class="fas fa-expand-alt mx-0 text-expand-icon-{{p.fullname}}"></i></button>
{% endif %}
<a class="list-inline-item" {% if v and v.newtab %}data-target="t" target="_blank"{% endif %} href="{{p.permalink}}">
@ -136,7 +136,7 @@
</li>
{% if p.realbody(v) %}
{% if p.realbody(v) or (p.embed and p.domain == "x.com") %}
<button type="button" class="list-inline-item ml-2" data-nonce="{{g.nonce}}" data-onclick="expandText('{{p.id}}')"><i class="fas fa-expand-alt mx-0 text-expand-icon-{{p.fullname}}"></i></button>
{% endif %}
@ -213,8 +213,11 @@
</div>
{% endif %}
{% if p.realbody(v) %}
{% if p.realbody(v) or (p.embed and p.domain == "x.com") %}
<div class="{% if p.chudded %}text-uppercase chud-img chud-{{p.id_last_num}}{% endif %} d-none card rounded border post-preview" id="post-text-{{p.id}}">
{% if p.domain == "x.com" %}
{{p.embed | safe}}
{% endif %}
{{p.realbody(v) | safe}}
</div>
{% endif %}