master
Aevann1 2021-10-05 23:56:50 +02:00
parent e08b82dc17
commit daf81b864d
1 changed files with 11 additions and 8 deletions

View File

@ -161,6 +161,7 @@ def sanitize(sanitized, noimages=False):
tag["style"] = "max-height: 100px; max-width: 100%;"
tag["class"] = "in-comment-image rounded-sm my-2"
tag["loading"] = "lazy"
tag["data-src"] = tag["src"]
link = soup.new_tag("a")
link["href"] = tag["src"]
@ -171,6 +172,8 @@ def sanitize(sanitized, noimages=False):
link["data-bs-toggle"] = "modal"
link["data-bs-target"] = "#expandImageModal"
tag["src"] = ""
tag.wrap(link)
#disguised link preventer
@ -220,10 +223,10 @@ def sanitize(sanitized, noimages=False):
if emoji.startswith("!"):
emoji = emoji[1:]
if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
new = re.sub(f'\w*(?<!"):!{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{emoji}:" title=":!{emoji}:" delay="0" height=60 src="https://{site}/assets/images/emojis/{emoji}.webp" style="transform: scaleX(-1)">', new)
new = re.sub(f'\w*(?<!"):!{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{emoji}:" title=":!{emoji}:" delay="0" height=60 src="" data-src="https://{site}/assets/images/emojis/{emoji}.webp" style="transform: scaleX(-1)">', new)
elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
new = re.sub(f'\w*(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" height=60 src="https://{site}/assets/images/emojis/{emoji}.webp">', new)
new = re.sub(f'\w*(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" height=60 src="" data-src="https://{site}/assets/images/emojis/{emoji}.webp">', new)
if emoji in session["favorite_emojis"]: session["favorite_emojis"][emoji] += 1
else: session["favorite_emojis"][emoji] = 1
@ -236,10 +239,10 @@ def sanitize(sanitized, noimages=False):
if emoji.startswith("!"):
emoji = emoji[1:]
if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
sanitized = re.sub(f'\w*(?<!"):!{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{emoji}:" title=":!{emoji}:" delay="0" height=30 src="https://{site}/assets/images/emojis/{emoji}.webp" style="transform: scaleX(-1)">', sanitized)
sanitized = re.sub(f'\w*(?<!"):!{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{emoji}:" title=":!{emoji}:" delay="0" height=30 src="" data-src="https://{site}/assets/images/emojis/{emoji}.webp" style="transform: scaleX(-1)">', sanitized)
elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
sanitized = re.sub(f'\w*(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" height=30 src="https://{site}/assets/images/emojis/{emoji}.webp">', sanitized)
sanitized = re.sub(f'\w*(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" height=30 src="" data-src="https://{site}/assets/images/emojis/{emoji}.webp">', sanitized)
if emoji in session["favorite_emojis"]: session["favorite_emojis"][emoji] += 1
else: session["favorite_emojis"][emoji] = 1
@ -251,22 +254,22 @@ def sanitize(sanitized, noimages=False):
for i in re.finditer('" target="_blank">(https://youtube.com/watch\?v\=.*?)</a>', sanitized):
url = i.group(1)
replacing = f'<a href="{url}" target="_blank">{url}</a>'
htmlsource = f'<div class="embed-responsive embed-responsive-16by9 mb-3"><iframe loading="lazy" src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>'
htmlsource = f'<div class="embed-responsive embed-responsive-16by9 mb-3"><iframe loading="lazy" src="" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>'
sanitized = sanitized.replace(replacing, htmlsource.replace("watch?v=", "embed/"))
for i in re.finditer('<a href="(https://streamable.com/e/.*?)"', sanitized):
url = i.group(1)
replacing = f'<a href="{url}" target="_blank">{url}</a>'
htmlsource = f'<div class="embed-responsive embed-responsive-16by9 mb-3"><iframe loading="lazy" src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>'
htmlsource = f'<div class="embed-responsive embed-responsive-16by9 mb-3"><iframe loading="lazy" src="" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>'
sanitized = sanitized.replace(replacing, htmlsource)
for i in re.finditer('<p>(https:.*?\.mp4)</p>', sanitized):
sanitized = sanitized.replace(i.group(0), f'<p><video controls loop preload="metadata" style="max-width: 100%"><source src="{i.group(1)}" type="video/mp4"></video>')
sanitized = sanitized.replace(i.group(0), f'<p><video controls loop preload="metadata" style="max-width: 100%"><source src="" data-src="{i.group(1)}" type="video/mp4"></video>')
for i in re.finditer('<a href="(https://open.spotify.com/embed/.*?)"', sanitized):
url = i.group(1)
replacing = f'<a href="{url}" target="_blank">{url}</a>'
htmlsource = f'<iframe src="{url}" width="100%" height="80" frameBorder="0" allowtransparency="true" allow="encrypted-media"></iframe>'
htmlsource = f'<iframe src="" data-src="{url}" width="100%" height="80" frameBorder="0" allowtransparency="true" allow="encrypted-media"></iframe>'
sanitized = sanitized.replace(replacing, htmlsource)
for rd in ["https://reddit.com/", "https://new.reddit.com/", "https://www.reddit.com/", "https://redd.it/"]: