reddit-save/html/main.js

36 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-01-03 03:26:38 +01:00
const toggleView = () => {
const postsSection = document.querySelector(".posts-section");
const commentsSection = document.querySelector(".comments-section");
if (commentsSection.style.display === "none") {
commentsSection.style.display = "block";
postsSection.style.display = "none";
} else {
postsSection.style.display = "block";
commentsSection.style.display = "none";
}
}
2021-01-03 04:01:13 +01:00
const toggleMedia = e => {
const img = e.target;
const preview = img.parentNode;
preview.classList.toggle("full");
}
2021-01-03 03:26:38 +01:00
window.addEventListener("load", function() {
2021-01-03 21:56:15 +01:00
const postsSection = document.querySelector(".posts-section");
const commentsSection = document.querySelector(".comments-section");
if (commentsSection) {
commentsSection.style.display = "none";
const toggleButton = document.createElement("button");
toggleButton.innerText = "toggle";
toggleButton.addEventListener("click", toggleView);
document.body.insertBefore(toggleButton, postsSection);
}
2021-01-03 04:01:13 +01:00
2021-01-03 21:56:15 +01:00
for (let preview of document.querySelectorAll(".preview")) {
const media = preview.querySelector("img") || preview.querySelector("video");
if (media) {
media.addEventListener("click", toggleMedia);
}
}
2021-01-03 03:26:38 +01:00
})