Add copy comment link on hold button, pause video if visiting comments

This commit is contained in:
John Stephani 2025-12-25 22:54:36 -06:00
parent 3b98b5ea06
commit 3d806c729c
1 changed files with 30 additions and 4 deletions

View File

@ -199,7 +199,7 @@
</div> </div>
{% endif %} {% endif %}
<span class="button-wrapper"> <span class="button-wrapper">
<button type="button" onclick='comments("{{ post.permalink }}")'>Comments</button> <button type="button" onpointerdown='commentsDown(this, "{{ post.permalink }}")' onpointerup='commentsUp(this, "{{ post.permalink }}")'>Comments</button>
<button type="button" onclick='hide(this, "{{ post.permalink }}")'>Hide</button> <button type="button" onclick='hide(this, "{{ post.permalink }}")'>Hide</button>
</span> </span>
</div> </div>
@ -285,10 +285,28 @@
} }
} }
function comments(permalink){ commentTimer = null;
window.open("https://reddit.com" + permalink, '_blank');
function commentsDown(button, permalink) {
commentTimer = setTimeout(() => {
navigator.clipboard.writeText("https://reddit.com" + permalink);
commentTimer = null;
button.textContent = "Copied!"
}, 500);
} }
function commentsUp(button, permalink) {
if (commentTimer != null) {
clearTimeout(commentTimer);
commentTimer = null;
pauseVideo(button);
window.open("https://reddit.com" + permalink, '_blank');
} else {
setTimeout(() => {
button.textContent = "Comments";
}, 500);
}
}
// text expand code // text expand code
function checkHeight(){ function checkHeight(){
@ -316,9 +334,17 @@
}); });
// audio/video sync code // audio/video sync code
function pauseVideo(element){
div = element.closest('.post');
video = div.querySelector('video:first-of-type');
if (video) {
video.pause();
pauseAudio(video);
}
}
function findAudio(video){ function findAudio(video){
const div = video.closest('.post'); div = video.closest('.post');
return div.querySelector('audio:first-of-type'); return div.querySelector('audio:first-of-type');
} }