forked from rDrama/rDrama
1
0
Fork 0
Aevann1 2022-07-23 11:08:02 +02:00
parent a4444c9402
commit f543abaaab
3 changed files with 44 additions and 52 deletions

View File

@ -231,26 +231,19 @@ function post_comment(fullname, hide){
try {data = JSON.parse(xhr.response)} try {data = JSON.parse(xhr.response)}
catch(e) {console.log(e)} catch(e) {console.log(e)}
if (data && data["comment"]) { if (data && data["comment"]) {
document.getElementById(hide).classList.add('d-none'); if (hide) document.getElementById(hide).classList.add('d-none');
let id = fullname.split('_')[1]; let id = fullname.split('_')[1];
let name = 'comment-form-space-' + fullname; let name = 'comment-form-space-' + fullname;
commentForm = document.getElementById(name); commentForm = document.getElementById(name);
let comments = document.getElementById('replies-of-' + id); let comments = document.getElementById('replies-of-' + fullname);
let comment = data["comment"].replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, ''); let comment = data["comment"].replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '');
comments.innerHTML = comment + comments.innerHTML; comments.innerHTML = comment + comments.innerHTML;
bs_trigger(commentForm); bs_trigger(commentForm);
let placeholder = document.getElementById("placeholder-comment");
if(placeholder){
comments.classList.remove('text-center');
comments.classList.remove('py-7');
placeholder.parentNode.removeChild(placeholder);
}
btn.disabled = false; btn.disabled = false;
btn.classList.remove('disabled'); btn.classList.remove('disabled');

View File

@ -89,7 +89,7 @@
{% if render_replies %} {% if render_replies %}
{% if level<9 or request.path.startswith('/notifications') or request.headers.get("xhr") %} {% if level<9 or request.path.startswith('/notifications') or request.headers.get("xhr") %}
<div id="replies-of-{{c.id}}"> <div id="replies-of-{{c.fullname}}">
{% for reply in replies %} {% for reply in replies %}
{{single_comment(reply, level=level+1)}} {{single_comment(reply, level=level+1)}}
{% endfor %} {% endfor %}
@ -598,7 +598,7 @@
{% if render_replies %} {% if render_replies %}
{% if level<9 or request.path.startswith('/notifications') or request.headers.get("xhr") %} {% if level<9 or request.path.startswith('/notifications') or request.headers.get("xhr") %}
<div id="replies-of-{{c.id}}"> <div id="replies-of-{{c.fullname}}">
{% for reply in replies %} {% for reply in replies %}
{{single_comment(reply, level=level+1)}} {{single_comment(reply, level=level+1)}}
{% endfor %} {% endfor %}
@ -636,7 +636,7 @@
</div> </div>
{% endif %} {% endif %}
{% else %} {% else %}
<div id="replies-of-{{c.id}}"></div> <div id="replies-of-{{c.fullname}}"></div>
{% endif %} {% endif %}
</div> </div>
@ -864,7 +864,7 @@
{% if v %} {% if v %}
<script src="{{asset('js/marked.js')}}"></script> <script src="{{asset('js/marked.js')}}"></script>
<script src="/assets/js/comments_v.js?v=285"></script> <script src="/assets/js/comments_v.js?v=286"></script>
{% endif %} {% endif %}
<script src="/assets/js/clipboard.js?v=250"></script> <script src="/assets/js/clipboard.js?v=250"></script>

View File

@ -1004,7 +1004,7 @@
<input autocomplete="off" id="file-upload-reply-{{p.fullname}}" accept="image/*, video/*, audio/*" type="file" multiple="multiple" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-reply-{{p.fullname}}','file-upload-reply-{{p.fullname}}')" hidden> <input autocomplete="off" id="file-upload-reply-{{p.fullname}}" accept="image/*, video/*, audio/*" type="file" multiple="multiple" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-reply-{{p.fullname}}','file-upload-reply-{{p.fullname}}')" hidden>
</label> </label>
</div> </div>
<a id="save-reply-to-{{p.fullname}}" role="button" form="reply-to-{{p.fullname}}" class="btn btn-primary text-whitebtn ml-auto fl-r" onclick="post_comment('{{p.fullname}}', 'comment-form-space-{{p.fullname}}');remove_dialog()">Comment</a> <a id="save-reply-to-{{p.fullname}}" role="button" form="reply-to-{{p.fullname}}" class="btn btn-primary text-whitebtn ml-auto fl-r" onclick="post_comment('{{p.fullname}}');remove_dialog()">Comment</a>
</form> </form>
<div id="form-preview-{{p.id}}" class="mb-3 mt-5"></div> <div id="form-preview-{{p.id}}" class="mb-3 mt-5"></div>
<div class="form-text text-small p-0 m-0"><a href="/formatting" {% if v and v.newtab and not g.webview %}target="_blank"{% endif %}>Formatting help</a></div> <div class="form-text text-small p-0 m-0"><a href="/formatting" {% if v and v.newtab and not g.webview %}target="_blank"{% endif %}>Formatting help</a></div>
@ -1026,51 +1026,50 @@
</div> </div>
{% endif %} {% endif %}
{% if p.replies %} {% if p.replies %}
<div class="comment-section" id="replies-of-{{p.id}}"> <div class="comment-section" id="replies-of-{{p.fullname}}">
{% with comments=p.replies %} {% with comments=p.replies %}
{% include "comments.html" %} {% include "comments.html" %}
{% endwith %} {% endwith %}
</div> </div>
{% if offset %} {% if offset %}
<script> <script>
function viewmore(pid,sort,offset,ids) { function viewmore(pid,sort,offset,ids) {
btn = document.getElementById("viewbtn"); btn = document.getElementById("viewbtn");
btn.disabled = true; btn.disabled = true;
btn.innerHTML = "Requesting..."; btn.innerHTML = "Requesting...";
const form = new FormData(); const form = new FormData();
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open("get", `/viewmore/${pid}/${sort}/${offset}?ids=${ids}`); xhr.open("get", `/viewmore/${pid}/${sort}/${offset}?ids=${ids}`);
xhr.setRequestHeader('xhr', 'xhr'); xhr.setRequestHeader('xhr', 'xhr');
xhr.onload=function(){ xhr.onload=function(){
if (xhr.status==200) { if (xhr.status==200) {
let e = document.getElementById(`viewmore-${offset}`); let e = document.getElementById(`viewmore-${offset}`);
e.innerHTML = xhr.response.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, ''); e.innerHTML = xhr.response.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '');
bs_trigger(e) bs_trigger(e)
comments = JSON.parse(localStorage.getItem("old-comment-counts")) || {} comments = JSON.parse(localStorage.getItem("old-comment-counts")) || {}
lastCount = comments['{{p.id}}'] lastCount = comments['{{p.id}}']
if (lastCount) if (lastCount)
{ {
{% for c in p.comments %} {% for c in p.comments %}
{% if not (v and v.id==c.author_id) and not c.voted %} {% if not (v and v.id==c.author_id) and not c.voted %}
if ({{c.created_utc*1000}} > lastCount.t) if ({{c.created_utc*1000}} > lastCount.t)
try {document.getElementById("comment-{{c.id}}-only").classList.add('unread')} try {document.getElementById("comment-{{c.id}}-only").classList.add('unread')}
catch(e) {} catch(e) {}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
}
} }
btn.disabled = false;
} }
btn.disabled = false; xhr.send(form)
} }
xhr.send(form) </script>
} {% endif %}
</script>
{% endif %}
{% elif not p.replies and p.deleted_utc == 0 %} {% elif not p.replies and p.deleted_utc == 0 %}
<div class="comment-section text-center py-7" id="replies-of-{{p.id}}"> <div class="comment-section text-center py-7" id="replies-of-{{p.fullname}}">
<span class="fa-stack fa-2x text-muted mb-4"> <span class="fa-stack fa-2x text-muted mb-4">
<i class="fas fa-square text-gray-500 opacity-25 fa-stack-2x"></i> <i class="fas fa-square text-gray-500 opacity-25 fa-stack-2x"></i>
<i class="fas text-gray-500 fa-ghost fa-stack-1x text-lg"></i> <i class="fas text-gray-500 fa-ghost fa-stack-1x text-lg"></i>