From 1cd22ec0d4414ee14e47ee43ec32631027f9f1be Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 5 Oct 2021 23:56:50 +0200 Subject: [PATCH] dsfsfd --- files/assets/js/default.js | 6 ++++++ files/assets/js/gif_modal.js | 39 ++++-------------------------------- files/helpers/sanitize.py | 19 ++++++++++-------- 3 files changed, 21 insertions(+), 43 deletions(-) diff --git a/files/assets/js/default.js b/files/assets/js/default.js index bd4006f23..167c28a36 100644 --- a/files/assets/js/default.js +++ b/files/assets/js/default.js @@ -1,3 +1,9 @@ +document.addEventListener("DOMContentLoaded", function () { + document.querySelectorAll('[data-src]').forEach(elem => { + elem.src = elem.dataset.src; + }) +}); + makeBold = function (form) { var text = document.getElementById(form); var startIndex = text.selectionStart, diff --git a/files/assets/js/gif_modal.js b/files/assets/js/gif_modal.js index 9214812ec..df47bec16 100644 --- a/files/assets/js/gif_modal.js +++ b/files/assets/js/gif_modal.js @@ -1,9 +1,3 @@ -document.addEventListener("DOMContentLoaded", function () { - document.querySelectorAll('[data-src]').forEach(elem => { - elem.src = elem.dataset.src; - }) -}); - async function getGif(searchTerm) { if (searchTerm !== undefined) { @@ -30,7 +24,7 @@ async function getGif(searchTerm) { container.innerHTML = ''; if (searchTerm == undefined) { - container.innerHTML = '
Agree
Laugh
Confused
Sad
Happy
Awesome
Yes
No
Love
Please
Scared
Angry
Awkward
Cringe
OMG
Why
Gross
Meh
' + container.innerHTML = '
Agree
Laugh
Confused
Sad
Happy
Awesome
Yes
No
Love
Please
Scared
Angry
Awkward
Cringe
OMG
Why
Gross
Meh
' backBtn.innerHTML = null; @@ -60,10 +54,10 @@ async function getGif(searchTerm) { for (var i = 0; i < 48; i++) { gifURL[i] = "https://media.giphy.com/media/" + data[i].id + "/200w_d.webp"; if (data[i].username==''){ - container.innerHTML += ('
'); + container.innerHTML += ('
'); } else { - container.innerHTML += ('
'); + container.innerHTML += ('
'); } noGIFs.innerHTML = null; loadGIFs.innerHTML = '

Thou've reached the end of the list!

'; @@ -82,29 +76,4 @@ function insertGIF(url,form) { commentBox.value = old + gif; - } - - document.getElementById('gifModal').addEventListener('hidden.bs.modal', function (e) { - - document.getElementById('gifSearch').value = null; - - var loadGIFs = document.getElementById('gifs-load-more'); - - var noGIFs = document.getElementById('no-gifs-found'); - - var container = document.getElementById('GIFs'); - - var backBtn = document.getElementById('gifs-back-btn'); - - var cancelBtn = document.getElementById('gifs-cancel-btn'); - - container.innerHTML = '
Agree
Laugh
Confused
Sad
Happy
Awesome
Yes
No
Love
Please
Scared
Angry
Awkward
Cringe
OMG
Why
Gross
Meh
' - - backBtn.innerHTML = null; - - cancelBtn.innerHTML = null; - - noGIFs.innerHTML = null; - - loadGIFs.innerHTML = null; -}); \ No newline at end of file +} \ No newline at end of file diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index db4daa9a8..33b78acd8 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -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*(?', new) + new = re.sub(f'\w*(?', new) elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): - new = re.sub(f'\w*(?', new) + new = re.sub(f'\w*(?', 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*(?', sanitized) + sanitized = re.sub(f'\w*(?', sanitized) elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'\w*(?', sanitized) + sanitized = re.sub(f'\w*(?', 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\=.*?)', sanitized): url = i.group(1) replacing = f'{url}' - htmlsource = f'
' + htmlsource = f'
' sanitized = sanitized.replace(replacing, htmlsource.replace("watch?v=", "embed/")) for i in re.finditer('{url}' - htmlsource = f'
' + htmlsource = f'
' sanitized = sanitized.replace(replacing, htmlsource) for i in re.finditer('

(https:.*?\.mp4)

', sanitized): - sanitized = sanitized.replace(i.group(0), f'

') + sanitized = sanitized.replace(i.group(0), f'

') for i in re.finditer('{url}' - htmlsource = f'' + htmlsource = f'' sanitized = sanitized.replace(replacing, htmlsource) for rd in ["https://reddit.com/", "https://new.reddit.com/", "https://www.reddit.com/", "https://redd.it/"]: