fuck with reddit tracking

master
Aevann 2024-08-16 22:38:00 +03:00
parent 06cd1670be
commit 1e7dbb3976
8 changed files with 33 additions and 24 deletions

View File

@ -7735,7 +7735,8 @@ img[src$="/e/speechbubble.webp"] {
margin-bottom: 10px;
}
iframe[src^='https://embed.reddit.com/r/'] {
.reddit-embed {
border: none;
display: inline !important;
width: 552px;
vertical-align: middle;

View File

@ -0,0 +1,27 @@
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
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" loading="lazy" height="500" src="${iframe_src}" credentialless="true" 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

View File

@ -592,10 +592,6 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=False, count_emojis
embed = embed.replace('<a href', '<a rel="nofollow noopener" href')
embed = BeautifulSoup(embed, 'lxml')
link.replaceWith(embed)
elif link["href"].startswith('https://old.reddit.com/r/') and not link["href"].endswith('/new/'):
embed = f'<a rel="nofollow noopener" class="reddit-embed-bq" data-embed-height="500" href="{link["href"]}">{link["href"]}</a>'
embed = BeautifulSoup(embed, 'lxml')
link.replaceWith(embed)
sanitized = str(soup).replace('<html><body>','').replace('</body></html>','').replace('/>','>')

View File

@ -125,5 +125,5 @@
{% else %}
<script defer src="{{'js/vendor/twitter.js' | asset}}"></script>
{% endif %}
<script defer src="{{'js/vendor/reddit.js' | asset}}"></script>
<script defer src="{{'js/reddit_embed.js' | asset}}"></script>
{% endblock %}

View File

@ -856,6 +856,6 @@
{% else %}
<script defer src="{{'js/vendor/twitter.js' | asset}}"></script>
{% endif %}
<script defer src="{{'js/vendor/reddit.js' | asset}}"></script>
<script defer src="{{'js/reddit_embed.js' | asset}}"></script>
</body>

View File

@ -137,5 +137,5 @@
{% else %}
<script defer src="{{'js/vendor/twitter.js' | asset}}"></script>
{% endif %}
<script defer src="{{'js/vendor/reddit.js' | asset}}"></script>
<script defer src="{{'js/reddit_embed.js' | asset}}"></script>
{% endblock %}

View File

@ -143,7 +143,7 @@
{% if p.url %}
{% if p.url.startswith('https://old.reddit.com/r/') and not p.url.endswith('/new/') %}
<a rel="nofollow noopener" class="reddit-embed-bq" data-embed-height="500" href="{{p.url}}"></a>
<a rel="nofollow noopener" href="{{p.url}}"></a>
<pre></pre>
{% elif p.url.startswith('https://tiktok.com/@') %}
{% set id = p.url.split('/video/')[1] %}