diff --git a/files/assets/js/comments+submission_listing.js b/files/assets/js/comments+submission_listing.js index 3ba9129d8..fbac0ed2e 100644 --- a/files/assets/js/comments+submission_listing.js +++ b/files/assets/js/comments+submission_listing.js @@ -18,7 +18,7 @@ function expandDesktopImage(image) { }; window.addEventListener("hashchange", function (e) { - if(window.location.hash != "#modal") { + if(location.hash != "#modal") { const expandImageModal = document.querySelector('#expandImageModal'); const modal = bootstrap.Modal.getInstance(expandImageModal); modal.hide(); @@ -26,7 +26,7 @@ window.addEventListener("hashchange", function (e) { }); document.getElementById('expandImageModal').addEventListener('hidden.bs.modal', function (e) { - if(window.location.hash == "#modal") { + if(location.hash == "#modal") { history.back(); } }); diff --git a/files/assets/js/emoji_modal.js b/files/assets/js/emoji_modal.js index 7d7429c47..579c78cba 100644 --- a/files/assets/js/emoji_modal.js +++ b/files/assets/js/emoji_modal.js @@ -915,7 +915,7 @@ function getEmoji(searchTerm) { const favorite_emojis = JSON.parse(localStorage.getItem("favorite_emojis")) || {} if (favorite_emojis[searchTerm]) favorite_emojis[searchTerm] += 1 else favorite_emojis[searchTerm] = 1 - window.localStorage.setItem("favorite_emojis", JSON.stringify(favorite_emojis)) + localStorage.setItem("favorite_emojis", JSON.stringify(favorite_emojis)) } function loadEmojis(form) { diff --git a/files/assets/js/new_comments_count.js b/files/assets/js/new_comments_count.js index 9cbfe8686..1ede4e54d 100644 --- a/files/assets/js/new_comments_count.js +++ b/files/assets/js/new_comments_count.js @@ -30,9 +30,9 @@ if (typeof showNewCommentCounts === 'undefined') { delete comments[key] } } - window.localStorage.setItem("comment-counts", JSON.stringify(comments)) + localStorage.setItem("comment-counts", JSON.stringify(comments)) } - window.localStorage.setItem(LAST_CACHE_CLEAN_ID, JSON.stringify(now)) + localStorage.setItem(LAST_CACHE_CLEAN_ID, JSON.stringify(now)) } setTimeout(cleanCache, 500) diff --git a/files/assets/js/pusher.js b/files/assets/js/pusher.js index 40dce5015..5898f3b0c 100644 --- a/files/assets/js/pusher.js +++ b/files/assets/js/pusher.js @@ -1337,7 +1337,7 @@ var PusherPushNotifications = (function (exports) { if (serviceWorkerRegistration) { var serviceWorkerScope = serviceWorkerRegistration.scope; - var currentURL = window.location.href; + var currentURL = location.href; var scopeMatchesCurrentPage = currentURL.startsWith(serviceWorkerScope); if (!scopeMatchesCurrentPage) { diff --git a/files/assets/js/submit.js b/files/assets/js/submit.js index a1a24a3c3..938f86b6a 100644 --- a/files/assets/js/submit.js +++ b/files/assets/js/submit.js @@ -43,6 +43,6 @@ document.getElementById('file-upload').addEventListener('change', function(){ function savetext() { let post_title = document.getElementById('post-title').value let post_text = document.getElementById('post-text').value - window.localStorage.setItem("post_title", post_title) - window.localStorage.setItem("post_text", post_text) + localStorage.setItem("post_title", post_title) + localStorage.setItem("post_text", post_text) } \ No newline at end of file diff --git a/files/assets/js/userpage.js b/files/assets/js/userpage.js index 67d74c030..7d4b04652 100644 --- a/files/assets/js/userpage.js +++ b/files/assets/js/userpage.js @@ -1,53 +1,68 @@ -let uid = document.getElementById('uid') +const playing = localStorage.getItem("playing") -if (uid) +if (!playing) { - uid = uid.innerHTML + let uid = document.getElementById('uid') - let audio = new Audio(`/songs/${uid}`); - audio.loop=true; - - function toggle() { - if (audio.paused) audio.play() - else audio.pause() - } - - audio.play(); - document.getElementById('userpage').addEventListener('click', () => { - if (audio.paused) audio.play(); - }, {once : true}); -} -else -{ - let uid = document.getElementById('vid') if (uid) { uid = uid.innerHTML - const paused = localStorage.getItem("paused") - let audio = new Audio(`/songs/${uid}`); audio.loop=true; - + function toggle() { - if (audio.paused) - { - audio.play() - localStorage.setItem("paused", "") - } - else - { - audio.pause() - localStorage.setItem("paused", "1") - } + if (audio.paused) audio.play() + else audio.pause() } - - if (!paused) + + audio.play(); + document.getElementById('userpage').addEventListener('click', () => { + if (audio.paused) audio.play(); + }, {once : true}); + + localStorage.setItem("playing", "1") + window.addEventListener("unload", function(e) { + localStorage.setItem("playing", "") + }); + } + else + { + let uid = document.getElementById('vid') + if (uid) { - audio.play(); - document.getElementById('userpage').addEventListener('click', () => { - if (audio.paused) audio.play(); - }, {once : true}); + uid = uid.innerHTML + + const paused = localStorage.getItem("paused") + + let audio = new Audio(`/songs/${uid}`); + audio.loop=true; + + function toggle() { + if (audio.paused) + { + audio.play() + localStorage.setItem("paused", "") + } + else + { + audio.pause() + localStorage.setItem("paused", "1") + } + } + + if (!paused) + { + audio.play(); + document.getElementById('userpage').addEventListener('click', () => { + if (audio.paused) audio.play(); + }, {once : true}); + + localStorage.setItem("playing", "1") + window.addEventListener("unload", function(e) { + localStorage.setItem("playing", "") + }); + } } } } \ No newline at end of file diff --git a/files/assets/js/userpage_v.js b/files/assets/js/userpage_v.js index bdc707e8b..1d9e0b0fe 100644 --- a/files/assets/js/userpage_v.js +++ b/files/assets/js/userpage_v.js @@ -161,7 +161,7 @@ function submitFormAjax(e) { myToast.show(); return true } else if (xhr.status >= 300 && xhr.status < 400) { - window.location.href = JSON.parse(xhr.response)["redirect"] + location.href = JSON.parse(xhr.response)["redirect"] } else { document.getElementById('toast-post-error-text').innerText = "Error, please try again later." try { diff --git a/files/templates/submission.html b/files/templates/submission.html index 870ad62c7..f031d4cbf 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -16,8 +16,8 @@ {% if success %} {% endif %} @@ -878,7 +878,7 @@ 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)) + localStorage.setItem("comment-counts", JSON.stringify(comments)) {% endif %} })() diff --git a/files/templates/submit.html b/files/templates/submit.html index 8469bcfff..46f8462c6 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -195,9 +195,9 @@ {% endblock %} + {% endblock %} diff --git a/files/templates/userpage_comments.html b/files/templates/userpage_comments.html index 1ca5a34ea..aca0b0d12 100644 --- a/files/templates/userpage_comments.html +++ b/files/templates/userpage_comments.html @@ -114,5 +114,5 @@