From c4db7eb30016c397b12d04bf0ff78b61e04a00a3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 10 Dec 2021 02:39:39 +0200 Subject: [PATCH] localstorage for emojis --- files/__main__.py | 1 + files/helpers/jinja2.py | 8 -------- files/helpers/sanitize.py | 15 --------------- files/templates/emoji_modal.html | 5 +---- files/templates/submission.html | 15 +++++++++++++++ files/templates/submission_listing.html | 8 ++++++++ 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index a1656c799..816ecfb11 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -122,6 +122,7 @@ def teardown_request(error): @app.after_request def after_request(response): + if session.get("favorite_emojis"): del session["favorite_emojis"] response.headers.add("Strict-Transport-Security", "max-age=31536000") response.headers.add("X-Frame-Options", "deny") diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 70913e02e..e0318c80f 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -22,14 +22,6 @@ def post_embed(id, v): return render_template("submission_listing.html", listing=[p], v=v) -@app.template_filter("favorite_emojis") -def favorite_emojis(x): - str = "" - emojis = sorted(x.items(), key=lambda x: x[1], reverse=True)[:25] - for k, v in emojis: - str += f'' - return str - @app.context_processor def inject_constants(): constants = [c for c in dir(const) if not c.startswith("_")] diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index ed8f2eac0..a18c0f455 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -164,11 +164,6 @@ def sanitize(sanitized, noimages=False): start = '<s>' end = '</s>' - try: - if not session.get("favorite_emojis"): session["favorite_emojis"] = {} - except: - pass - if start in sanitized and end in sanitized and start in sanitized.split(end)[0] and end in sanitized.split(start)[1]: sanitized = sanitized.replace(start, '').replace(end, '') for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized): @@ -192,9 +187,6 @@ def sanitize(sanitized, noimages=False): if path.isfile(f'./files/assets/images/emojis/{remoji}.webp'): new = re.sub(f'(?', new) - - if remoji in session["favorite_emojis"]: session["favorite_emojis"][remoji] += 1 - else: session["favorite_emojis"][remoji] = 1 sanitized = sanitized.replace(old, new) @@ -205,16 +197,9 @@ def sanitize(sanitized, noimages=False): emoji = emoji[1:] if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): sanitized = re.sub(f'(?', sanitized) - - if emoji in session["favorite_emojis"]: session["favorite_emojis"][emoji] += 1 - else: session["favorite_emojis"][emoji] = 1 elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): sanitized = re.sub(f'(?', sanitized) - - if emoji in session["favorite_emojis"]: session["favorite_emojis"][emoji] += 1 - else: session["favorite_emojis"][emoji] = 1 - sanitized = sanitized.replace("https://www.", "https://").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").replace("https://open.spotify.com/", "https://open.spotify.com/embed/").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=").replace("https://mobile.twitter", "https://twitter").replace("https://m.facebook", "https://facebook").replace("https://m.wikipedia", "https://wikipedia").replace("https://m.youtube", "https://youtube") diff --git a/files/templates/emoji_modal.html b/files/templates/emoji_modal.html index ccae485ac..9be7e5b4e 100644 --- a/files/templates/emoji_modal.html +++ b/files/templates/emoji_modal.html @@ -48,9 +48,6 @@
- {% if session.get("favorite_emojis") %} - {{session.get("favorite_emojis") | favorite_emojis | safe}} - {% endif %}
@@ -84,7 +81,7 @@
- +