localstorage for emojis

remotes/1693045480750635534/spooky-22
Aevann1 2021-12-10 02:39:39 +02:00
parent c553769008
commit c4db7eb300
6 changed files with 25 additions and 27 deletions

View File

@ -122,6 +122,7 @@ def teardown_request(error):
@app.after_request @app.after_request
def after_request(response): 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("Strict-Transport-Security", "max-age=31536000")
response.headers.add("X-Frame-Options", "deny") response.headers.add("X-Frame-Options", "deny")

View File

@ -22,14 +22,6 @@ def post_embed(id, v):
return render_template("submission_listing.html", listing=[p], v=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'<button class="btn m-1 px-0 emoji2" onclick="getEmoji(\'{k}\')" data-bs-toggle="tooltip" title=":{k}:" delay:="0"><img loading="lazy" width=50 src="/assets/images/emojis/{k}.webp" alt="{k}-emoji"></button>'
return str
@app.context_processor @app.context_processor
def inject_constants(): def inject_constants():
constants = [c for c in dir(const) if not c.startswith("_")] constants = [c for c in dir(const) if not c.startswith("_")]

View File

@ -164,11 +164,6 @@ def sanitize(sanitized, noimages=False):
start = '&lt;s&gt;' start = '&lt;s&gt;'
end = '&lt;/s&gt;' end = '&lt;/s&gt;'
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, '<span class="spoiler">').replace(end, '</span>') 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, '<span class="spoiler">').replace(end, '</span>')
for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized): for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized):
@ -193,9 +188,6 @@ def sanitize(sanitized, noimages=False):
if path.isfile(f'./files/assets/images/emojis/{remoji}.webp'): if path.isfile(f'./files/assets/images/emojis/{remoji}.webp'):
new = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" {classes}src="https://{site}/assets/images/emojis/{remoji}.webp" >', new) new = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" {classes}src="https://{site}/assets/images/emojis/{remoji}.webp" >', new)
if remoji in session["favorite_emojis"]: session["favorite_emojis"][remoji] += 1
else: session["favorite_emojis"][remoji] = 1
sanitized = sanitized.replace(old, new) sanitized = sanitized.replace(old, new)
@ -206,16 +198,9 @@ def sanitize(sanitized, noimages=False):
if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
sanitized = re.sub(f'(?<!"):!{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{emoji}:" title=":!{emoji}:" delay="0" height=30 class="emj mirrored" src="https://{site}/assets/images/emojis/{emoji}.webp">', sanitized) sanitized = re.sub(f'(?<!"):!{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{emoji}:" title=":!{emoji}:" delay="0" height=30 class="emj mirrored" 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
elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
sanitized = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" height=30 class="emj" src="https://{site}/assets/images/emojis/{emoji}.webp">', sanitized) sanitized = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" height=30 class="emj" 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
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") 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")
if "https://youtube.com/watch?v=" in sanitized: sanitized = sanitized.replace("?t=", "&t=") if "https://youtube.com/watch?v=" in sanitized: sanitized = sanitized.replace("?t=", "&t=")

View File

@ -48,9 +48,6 @@
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane fade show active" id="emoji-tab-favorite"> <div class="tab-pane fade show active" id="emoji-tab-favorite">
<div class="d-flex flex-wrap py-3 pl-2" id="EMOJIS_favorite"> <div class="d-flex flex-wrap py-3 pl-2" id="EMOJIS_favorite">
{% if session.get("favorite_emojis") %}
{{session.get("favorite_emojis") | favorite_emojis | safe}}
{% endif %}
</div> </div>
</div> </div>
<div class="tab-pane fade" id="emoji-tab-marsey"> <div class="tab-pane fade" id="emoji-tab-marsey">
@ -84,7 +81,7 @@
</div> </div>
</div> </div>
<script src="/assets/js/emoji_modal.js?v=140"></script> <script src="/assets/js/emoji_modal.js?v=146"></script>
<style> <style>
a.emojitab { a.emojitab {

View File

@ -869,4 +869,19 @@
{% endif %} {% endif %}
<script>
(() => {
{% if (not v or v.highlightcomments) %}
showNewCommentCounts('{{p.id}}', {{p.comment_count}})
{% endif %}
{% if "?context" not in request.full_path %}
const comments = JSON.parse(localStorage.getItem("comment-counts")) || {}
const newTotal = {{p.comment_count}} || ((comments['{{p.id}}'] || { c: 0 }).c + 1)
comments['{{p.id}}'] = { c: newTotal, t: Date.now() }
window.localStorage.setItem("comment-counts", JSON.stringify(comments))
{% endif %}
})()
</script>
{% endblock %} {% endblock %}

View File

@ -55,6 +55,14 @@
</div> </div>
</div> </div>
<script>
(() => {
{% if (not v or v.highlightcomments) %}
showNewCommentCounts('{{p.id}}', {{p.comment_count}})
{% endif %}
})()
</script>
{% set ups=p.upvotes %} {% set ups=p.upvotes %}
{% set downs=p.downvotes %} {% set downs=p.downvotes %}
{% set score=ups-downs %} {% set score=ups-downs %}