make reddit embeds work on new.reddit.com, sh.reddit.com, reddit.com

master
Aevann 2024-08-23 16:13:34 +03:00
parent 8d90b7dadd
commit f9669e94d8
4 changed files with 9 additions and 2 deletions

View File

@ -1,11 +1,15 @@
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"])')) {
const reddit = document.getElementById('reddit').value
if (reddit == "undelete.pullpush.io") return
for (const a of document.querySelectorAll(`a[href^="https://${reddit}/r/"]:not(a[href$="/new"])`)) {
if (a.innerHTML && a.innerHTML !== a.href) continue
if (["STRONG", "LI", "BLOCKQUOTE", "PRE", "CODEBLOCK"].includes(a.parentElement.tagName)) continue
let iframe_src = a.href.replace('https://old.reddit.com/', 'https://embed.reddit.com/')
let iframe_src = a.href.replace(`https://${reddit}/`, 'https://embed.reddit.com/')
iframe_src = iframe_src.split('?')[0]
iframe_src += "?context=1&showtitle=true"
if (document.body.dataset.dark)

View File

@ -121,5 +121,6 @@
<script defer src="{{'js/chat.js' | asset}}"></script>
{% endif %}
<script defer src="{{'js/vendor/twitter.js' | asset}}"></script>
<input id="reddit" hidden value="{{v.reddit}}">
<script defer src="{{'js/reddit_embed.js' | asset}}"></script>
{% endblock %}

View File

@ -857,6 +857,7 @@
{% endif %}
<script defer src="{{'js/vendor/twitter.js' | asset}}"></script>
<input id="reddit" hidden value="{{v.reddit if v else 'old.reddit.com'}}">
<script defer src="{{'js/reddit_embed.js' | asset}}"></script>
</body>

View File

@ -133,5 +133,6 @@
<script defer src="{{'js/chat.js' | asset}}"></script>
{% endif %}
<script defer src="{{'js/vendor/twitter.js' | asset}}"></script>
<input id="reddit" hidden value="{{v.reddit}}">
<script defer src="{{'js/reddit_embed.js' | asset}}"></script>
{% endblock %}