forked from rDrama/rDrama
Merge branch 'master' of https://github.com/Aevann1/Drama
commit
a78978044d
|
@ -33,6 +33,8 @@
|
||||||
<script src="/assets/js/comments_admin.js"></script>
|
<script src="/assets/js/comments_admin.js"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% include 'embeds/new_comments_count.html' %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function collapse_comment(comment_id) {
|
function collapse_comment(comment_id) {
|
||||||
|
@ -64,11 +66,6 @@
|
||||||
{% macro single_comment(c, level=1) %}
|
{% macro single_comment(c, level=1) %}
|
||||||
<!---beginning of comment {{c.id}}--->
|
<!---beginning of comment {{c.id}}--->
|
||||||
|
|
||||||
<script>
|
|
||||||
var date = new Date('{{c.created_datetime}}');
|
|
||||||
document.getElementById('timestamp-{{c.id}}').title = date.toString();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{% set ups=c.upvotes %}
|
{% set ups=c.upvotes %}
|
||||||
{% set downs=c.downvotes %}
|
{% set downs=c.downvotes %}
|
||||||
{% set score=ups-downs %}
|
{% set score=ups-downs %}
|
||||||
|
@ -434,10 +431,10 @@
|
||||||
<input id="file-upload-reply-{{c.fullname}}" type="file" name="file" accept="image/*" onchange="document.getElementById('filename-show-reply-{{c.id}}').innerHTML='image';" hidden>
|
<input id="file-upload-reply-{{c.fullname}}" type="file" name="file" accept="image/*" onchange="document.getElementById('filename-show-reply-{{c.id}}').innerHTML='image';" hidden>
|
||||||
</label>
|
</label>
|
||||||
<a href="javascript:void(0)" onclick="document.getElementById('reply-to-{{c.id}}').classList.add('d-none')" class="d-none d-md-block btn btn-link text-muted ml-auto cancel-form">Cancel</a>
|
<a href="javascript:void(0)" onclick="document.getElementById('reply-to-{{c.id}}').classList.add('d-none')" class="d-none d-md-block btn btn-link text-muted ml-auto cancel-form">Cancel</a>
|
||||||
<a id="save-reply-to-{{c.fullname}}" class="d-none d-md-block btn btn-primary text-white ml-2" onclick="post_comment('{{c.fullname}}');" href="javascript:void(0)">Comment</a>
|
<a id="save-reply-to-{{c.fullname}}" class="d-none d-md-block btn btn-primary text-white ml-2" onclick="post_comment('{{c.fullname}}', '{{c.post.id}}');" href="javascript:void(0)">Comment</a>
|
||||||
</div>
|
</div>
|
||||||
<a href="javascript:void(0)" onclick="document.getElementById('reply-to-{{c.id}}').classList.add('d-none')" class="d-block d-md-none btn btn-link text-muted ml-auto cancel-form">Cancel</a>
|
<a href="javascript:void(0)" onclick="document.getElementById('reply-to-{{c.id}}').classList.add('d-none')" class="d-block d-md-none btn btn-link text-muted ml-auto cancel-form">Cancel</a>
|
||||||
<a id="save-reply-to-{{c.fullname}}" class="d-block d-md-none btn btn-primary text-white ml-2" onclick="post_comment('{{c.fullname}}');" href="javascript:void(0)">Comment</a>
|
<a id="save-reply-to-{{c.fullname}}" class="d-block d-md-none btn btn-primary text-white ml-2" onclick="post_comment('{{c.fullname}}', '{{c.post.id}}');" href="javascript:void(0)">Comment</a>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -551,6 +548,13 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(() => {
|
||||||
|
const date = new Date('{{c.created_datetime}}');
|
||||||
|
document.getElementById('timestamp-{{c.id}}').title = date.toString();
|
||||||
|
})()
|
||||||
|
</script>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
<script>
|
||||||
|
|
||||||
|
// only allows the script to execute once
|
||||||
|
if (typeof showNewCommentCounts === 'undefined') {
|
||||||
|
|
||||||
|
// localstorage comment counts format: {"<postId>": {c: <totalComments>, t: <timestampUpdated>}}
|
||||||
|
const COMMENT_COUNTS_ID = "comment-counts"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the number of new comments present since the last time the post was opened
|
||||||
|
*/
|
||||||
|
function showNewCommentCounts(postId, newTotal) {
|
||||||
|
const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {}
|
||||||
|
|
||||||
|
const lastCount = comments[postId]
|
||||||
|
if (lastCount) {
|
||||||
|
const newComments = newTotal - lastCount.c
|
||||||
|
if (newComments > 0) {
|
||||||
|
document.querySelectorAll(`#post-${postId} .new-comments`).forEach(elem => {
|
||||||
|
elem.textContent = ` (+${newComments})`
|
||||||
|
elem.classList.remove("d-none")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function incrementCommentCount(postId) {
|
||||||
|
saveCommentsCount(postId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the comment count to the localStorage
|
||||||
|
*
|
||||||
|
* @param postId The id of the post associated with the comments
|
||||||
|
* @param lastTotalComs The new amount, If null it will just increment the previous amount
|
||||||
|
*/
|
||||||
|
function saveCommentsCount(postId, lastTotalComs = null) {
|
||||||
|
const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {}
|
||||||
|
|
||||||
|
const newTotal = lastTotalComs || ((comments[postId] || { c: 0 }).c + 1)
|
||||||
|
|
||||||
|
comments[postId] = { c: newTotal, t: Date.now() }
|
||||||
|
|
||||||
|
window.localStorage.setItem(COMMENT_COUNTS_ID, JSON.stringify(comments))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans the expired entries (5 days). It runs every hour.
|
||||||
|
*/
|
||||||
|
function cleanCommentsCache() {
|
||||||
|
const LAST_CACHE_CLEAN_ID = "last-cache-clean"
|
||||||
|
const EXPIRE_INTERVAL_MILLIS = 5 * 24 * 60 * 60 * 1000
|
||||||
|
const CACHE_CLEAN_INTERVAL = 60 * 60 * 1000 // 1 hour
|
||||||
|
|
||||||
|
function cleanCache() {
|
||||||
|
const lastCacheClean = JSON.parse(localStorage.getItem(LAST_CACHE_CLEAN_ID)) || Date.now()
|
||||||
|
const now = Date.now()
|
||||||
|
|
||||||
|
if (now - lastCacheClean > CACHE_CLEAN_INTERVAL) {
|
||||||
|
const comments = JSON.parse(localStorage.getItem(COMMENT_COUNTS_ID)) || {}
|
||||||
|
|
||||||
|
for (let [key, value] of Object.entries(comments)) {
|
||||||
|
if (now - value.t > EXPIRE_INTERVAL_MILLIS) {
|
||||||
|
delete comments[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.localStorage.setItem(COMMENT_COUNTS_ID, JSON.stringify(comments))
|
||||||
|
}
|
||||||
|
window.localStorage.setItem(LAST_CACHE_CLEAN_ID, JSON.stringify(now))
|
||||||
|
}
|
||||||
|
|
||||||
|
// So it does not slow the load of the main page with the clean up
|
||||||
|
setTimeout(cleanCache, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanCommentsCache()
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -33,15 +33,6 @@
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<script>
|
|
||||||
var date = new Date('{{p.created_datetime}}');
|
|
||||||
document.getElementById('timestamp').title = date.toString();
|
|
||||||
{% if p.edited_utc %}
|
|
||||||
var date = new Date('{{p.edited_datetime}}');
|
|
||||||
document.getElementById('edited_timestamp').title = date.toString();
|
|
||||||
{% endif %}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{% if p.award_count("shit") %}
|
{% if p.award_count("shit") %}
|
||||||
<script src="/assets/js/bug-min.js"></script>
|
<script src="/assets/js/bug-min.js"></script>
|
||||||
{% set minbugs = 10*p.award_count("shit") if p.award_count("shit") < 3 else 20 %}
|
{% set minbugs = 10*p.award_count("shit") if p.award_count("shit") < 3 else 20 %}
|
||||||
|
@ -73,6 +64,8 @@
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% include 'embeds/new_comments_count.html' %}
|
||||||
|
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta property="og:type" content="article" />
|
<meta property="og:type" content="article" />
|
||||||
|
|
||||||
|
@ -402,7 +395,12 @@
|
||||||
<div class="post-actions mt-2">
|
<div class="post-actions mt-2">
|
||||||
<ul class="list-inline text-right d-flex">
|
<ul class="list-inline text-right d-flex">
|
||||||
|
|
||||||
<li class="list-inline-item"><a {% if v %}href="{{p.permalink}}"{% else %}href="/logged_out{{p.permalink}}"{% endif %}><i class="fas fa-comment-dots"></i>{{p.comment_count}}</a></li>
|
<li class="list-inline-item">
|
||||||
|
<a {% if v %}href="{{p.permalink}}"{% else %}href="/logged_out{{p.permalink}}"{% endif %}>
|
||||||
|
<i class="fas fa-comment-dots"></i>{{p.comment_count}}
|
||||||
|
<span class="text-info d-none new-comments"></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
{% if v and v.id==p.author_id %}
|
{% if v and v.id==p.author_id %}
|
||||||
{% if p.private %}
|
{% if p.private %}
|
||||||
|
@ -540,7 +538,12 @@
|
||||||
<div class="post-actions">
|
<div class="post-actions">
|
||||||
<ul class="list-inline text-right d-flex">
|
<ul class="list-inline text-right d-flex">
|
||||||
|
|
||||||
<li class="list-inline-item mr-auto"><a {% if v %}href="{{p.permalink}}"{% else %}href="/logged_out{{p.permalink}}"{% endif %}><i class="fas fa-comment-dots"></i>{{p.comment_count}}</a></li>
|
<li class="list-inline-item mr-auto">
|
||||||
|
<a {% if v %}href="{{p.permalink}}"{% else %}href="/logged_out{{p.permalink}}"{% endif %}>
|
||||||
|
<i class="fas fa-comment-dots"></i>{{p.comment_count}}
|
||||||
|
<span class="text-info d-none new-comments"></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li class="list-inline-item"><a href="javascript:void(0);" role="button" class="copy-link" data-clipboard-text="{% if 'rdrama' in request.host %}https://taytay.life{{p.permalink}}{% else %}{{p.permalink | full_link}}{% endif %}"><i class="fas fa-link"></i>Copy link</a></li>
|
<li class="list-inline-item"><a href="javascript:void(0);" role="button" class="copy-link" data-clipboard-text="{% if 'rdrama' in request.host %}https://taytay.life{{p.permalink}}{% else %}{{p.permalink | full_link}}{% endif %}"><i class="fas fa-link"></i>Copy link</a></li>
|
||||||
{% if v %}
|
{% if v %}
|
||||||
|
@ -577,6 +580,25 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// closure to avoid variable conflicts
|
||||||
|
(() => {
|
||||||
|
const date = new Date('{{p.created_datetime}}');
|
||||||
|
document.getElementById('timestamp').title = date.toString();
|
||||||
|
{% if p.edited_utc %}
|
||||||
|
const dateEdited = new Date('{{p.edited_datetime}}');
|
||||||
|
document.getElementById('edited_timestamp').title = dateEdited.toString();
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if (not v or v.highlightcomments) %}
|
||||||
|
showNewCommentCounts('{{p.id}}', {{p.comment_count}})
|
||||||
|
{% endif %}
|
||||||
|
saveCommentsCount('{{p.id}}', {{p.comment_count}})
|
||||||
|
})()
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
<div class="row border-md-0 comment-section pb-3">
|
<div class="row border-md-0 comment-section pb-3">
|
||||||
<div class="col border-top">
|
<div class="col border-top">
|
||||||
<div class="comments-count py-3">
|
<div class="comments-count py-3">
|
||||||
|
@ -634,7 +656,7 @@
|
||||||
<input type="checkbox" class="custom-control-input" id="nsfwCheck-{{p.fullname}}" name="over_18" form="reply-to-{{p.fullname}}">
|
<input type="checkbox" class="custom-control-input" id="nsfwCheck-{{p.fullname}}" name="over_18" form="reply-to-{{p.fullname}}">
|
||||||
<label class="custom-control-label" for="nsfwCheck">+18</label>
|
<label class="custom-control-label" for="nsfwCheck">+18</label>
|
||||||
</div>
|
</div>
|
||||||
--> <a id="save-reply-to-{{p.fullname}}" href="javascript:void(0)" form="reply-to-{{p.fullname}}" class="btn btn-primary text-whitebtn ml-auto" onclick="post_comment('{{p.fullname}}')">Comment</a>
|
--> <a id="save-reply-to-{{p.fullname}}" href="javascript:void(0)" form="reply-to-{{p.fullname}}" class="btn btn-primary text-whitebtn ml-auto" onclick="post_comment('{{p.fullname}}', '{{p.id}}')">Comment</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,16 +15,9 @@
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% for p in listing %}
|
{% include 'embeds/new_comments_count.html' %}
|
||||||
|
|
||||||
<script>
|
{% for p in listing %}
|
||||||
var date = new Date('{{p.created_datetime}}');
|
|
||||||
document.getElementById('timestamp-{{p.id}}').title = date.toString();
|
|
||||||
{% if p.edited_utc %}
|
|
||||||
var date = new Date('{{p.edited_datetime}}');
|
|
||||||
document.getElementById('edited_timestamp-{{p.id}}').title = date.toString();
|
|
||||||
{% endif %}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{% set ups=p.upvotes %}
|
{% set ups=p.upvotes %}
|
||||||
{% set downs=p.downvotes %}
|
{% set downs=p.downvotes %}
|
||||||
|
@ -147,8 +140,12 @@
|
||||||
{% if p.realbody(v) %}
|
{% if p.realbody(v) %}
|
||||||
<li class="list-inline-item"><a href="javascript:void(0)" class="text-expand" data-bs-id="{{p.id}}"><i class="fas fa-expand-alt mr-0 text-expand-icon-{{p.id}}"></i></a></li>
|
<li class="list-inline-item"><a href="javascript:void(0)" class="text-expand" data-bs-id="{{p.id}}"><i class="fas fa-expand-alt mr-0 text-expand-icon-{{p.id}}"></i></a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li class="list-inline-item"><a {% if v and v.newtab %}target="_blank"{% endif %} {% if v %}href="{{p.permalink}}"{% else %}href="/logged_out{{p.permalink}}"{% endif %}><i class="fas fa-comment-dots"></i>{{p.comment_count}}</a></li>
|
<li class="list-inline-item">
|
||||||
|
<a {% if v and v.newtab %}target="_blank"{% endif %} {% if v %}href="{{p.permalink}}"{% else %}href="/logged_out{{p.permalink}}"{% endif %}>
|
||||||
|
<i class="fas fa-comment-dots"></i>{{p.comment_count}}
|
||||||
|
<span class="text-info d-none new-comments"></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li class="list-inline-item"><a href="/votes?link={{p.fullname}}"><i class="fas fa-arrows-v"></i>Votes</a></li>
|
<li class="list-inline-item"><a href="/votes?link={{p.fullname}}"><i class="fas fa-arrows-v"></i>Votes</a></li>
|
||||||
|
|
||||||
{% if v and v.id!=p.author_id %}
|
{% if v and v.id!=p.author_id %}
|
||||||
|
@ -233,8 +230,12 @@
|
||||||
<div class="card-footer d-block d-md-none mt-2">
|
<div class="card-footer d-block d-md-none mt-2">
|
||||||
<div class="post-actions">
|
<div class="post-actions">
|
||||||
<ul class="list-inline text-right d-flex">
|
<ul class="list-inline text-right d-flex">
|
||||||
<li class="list-inline-item mr-auto"><a {% if v and v.newtab %}target="_blank"{% endif %} {% if v %}href="{{p.permalink}}"{% else %}href="/logged_out{{p.permalink}}"{% endif %}><i class="fas fa-comment-dots"></i>{{p.comment_count}}</a></li>
|
<li class="list-inline-item mr-auto">
|
||||||
|
<a {% if v and v.newtab %}target="_blank"{% endif %} {% if v %}href="{{p.permalink}}"{% else %}href="/logged_out{{p.permalink}}"{% endif %}>
|
||||||
|
<i class="fas fa-comment-dots"></i>{{p.comment_count}}
|
||||||
|
<span class="text-info d-none new-comments"></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li class="list-inline-item"><a href="javascript:void(0);" role="button" class="copy-link" data-clipboard-text="{% if 'rdrama' in request.host %}https://taytay.life{{p.permalink}}{% else %}{{p.permalink | full_link}}{% endif %}"><i class="fas fa-link"></i>Copy link</a></li>
|
<li class="list-inline-item"><a href="javascript:void(0);" role="button" class="copy-link" data-clipboard-text="{% if 'rdrama' in request.host %}https://taytay.life{{p.permalink}}{% else %}{{p.permalink | full_link}}{% endif %}"><i class="fas fa-link"></i>Copy link</a></li>
|
||||||
|
|
||||||
{% if p.realbody(v) and request.path != "/changelog"%}
|
{% if p.realbody(v) and request.path != "/changelog"%}
|
||||||
|
@ -395,6 +396,21 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(() => {
|
||||||
|
const date = new Date('{{p.created_datetime}}');
|
||||||
|
document.getElementById('timestamp-{{p.id}}').title = date.toString();
|
||||||
|
{% if p.edited_utc %}
|
||||||
|
const dateEdited = new Date('{{p.edited_datetime}}');
|
||||||
|
document.getElementById('edited_timestamp-{{p.id}}').title = dateEdited.toString();
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if (not v or v.highlightcomments) %}
|
||||||
|
showNewCommentCounts('{{p.id}}', {{p.comment_count}})
|
||||||
|
{% endif %}
|
||||||
|
})()
|
||||||
|
</script>
|
||||||
|
|
||||||
{% if p.active_flags %}
|
{% if p.active_flags %}
|
||||||
<div id="flaggers-{{p.id}}" class="flaggers d-none">
|
<div id="flaggers-{{p.id}}" class="flaggers d-none">
|
||||||
<strong><i class="far fa-fw fa-flag"></i> Reported by:</strong>
|
<strong><i class="far fa-fw fa-flag"></i> Reported by:</strong>
|
||||||
|
|
Loading…
Reference in New Issue