forked from MarseyWorld/MarseyWorld
localstorage for emojis
parent
c553769008
commit
c4db7eb300
|
@ -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")
|
||||
|
|
|
@ -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'<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
|
||||
def inject_constants():
|
||||
constants = [c for c in dir(const) if not c.startswith("_")]
|
||||
|
|
|
@ -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, '<span class="spoiler">').replace(end, '</span>')
|
||||
|
||||
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'(?<!"):{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)
|
||||
|
||||
|
@ -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'(?<!"):!{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'):
|
||||
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")
|
||||
|
||||
|
|
|
@ -48,9 +48,6 @@
|
|||
<div class="tab-content">
|
||||
<div class="tab-pane fade show active" id="emoji-tab-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 class="tab-pane fade" id="emoji-tab-marsey">
|
||||
|
@ -84,7 +81,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/assets/js/emoji_modal.js?v=140"></script>
|
||||
<script src="/assets/js/emoji_modal.js?v=146"></script>
|
||||
|
||||
<style>
|
||||
a.emojitab {
|
||||
|
|
|
@ -869,4 +869,19 @@
|
|||
{% 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 %}
|
|
@ -55,6 +55,14 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(() => {
|
||||
{% if (not v or v.highlightcomments) %}
|
||||
showNewCommentCounts('{{p.id}}', {{p.comment_count}})
|
||||
{% endif %}
|
||||
})()
|
||||
</script>
|
||||
|
||||
{% set ups=p.upvotes %}
|
||||
{% set downs=p.downvotes %}
|
||||
{% set score=ups-downs %}
|
||||
|
|
Loading…
Reference in New Issue