Text



`;
const svgCheck = ``;
function addImageModal() {
const div = document.createElement("div");
div.id = "myModal";
div.className = "modal";
div.innerHTML = `×
`;
document.body.appendChild(div);
// Get elements
const modal = document.getElementById("myModal");
const img = document.getElementById("myImg");
const modalImg = document.getElementById("imgInModal");
const imgCaption = document.getElementById("imgCaption");
const closeBtn = document.getElementsByClassName("close")[0];
// On image click, open modal
document.querySelectorAll(".post-body-container img").forEach((img) => {
const parent = img?.parentElement?.parentElement;
console.log(parent);
img.onclick = () => {
modal.style.display = "flex";
if (parent && parent.childElementCount > 1) {
const items = [];
Array.from(parent.childNodes).map((v) => {
const text = v.innerText;
if (!text) return;
text.split("|").forEach((v) => {
v = v.trim();
if (!v) return;
items.push(v);
});
});
if (items.length) {
imgCaption.innerHTML =
"" + items.map((v) => `- ${v}
`).join("\n") + "
";
imgCaption.style.display = "block";
} else {
imgCaption.style.display = "none";
}
} else {
imgCaption.style.display = "none";
}
modalImg.src = img.src;
};
});
// On close button click
closeBtn.onclick = () => {
modal.style.display = "none";
};
// Close modal when clicking outside the image
modal.onclick = (event) => {
if (event.target === modal) {
modal.style.display = "none";
}
};
}
const updatePostViews = async () => {
const sharing =
document.querySelector(".post-view .post-header") ||
document.querySelector(".post-view .sharing") ||
document.querySelector(".page-view .post-header") ||
document.querySelector(".page-view .sharing");
if (!sharing) return;
const svg = ``;
const eye = `visibility`;
const createViews = (views = "...") => {
const element = document.createElement("div");
element.innerHTML = `${svg}${views}
`;
return element;
};
let start = 3;
let loading = null;
let element = createViews("...");
sharing.style.display = "flex";
sharing.style.justifyContent = "space-between";
sharing.appendChild(element);
start--;
loading = setInterval(() => {
const views = Array(start).fill(".").join("");
element.querySelector("span").innerText = views;
start--;
if (start === 0) {
start = 3;
}
}, 1000);
const url =
"https://script.google.com/macros/s/AKfycbwcSfr5fbWUeoNV9hFex6TX_jN9IPpBl4t-HTMZHVR6xqtU9phcSKd5XJXopjf_fPOfNw/exec";
const href = location.href;
const api = `${url}?url=${href}`;
const data = await fetch(api);
const { views } = await data.json();
loading && clearInterval(loading);
element.querySelector("span").innerText = views;
};
function addBackToTopButton() {
const backToTopSvg = ``;
const backToTop = document.createElement("div");
backToTop.innerHTML = `
${backToTopSvg}
Back to Top`;
document.querySelector(".post-body-container").appendChild(backToTop);
}
function copyToClipboard(button, url) {
navigator.clipboard.writeText(url).then(() => {
const text = button.innerText;
button.innerText = "Copied";
setTimeout(() => {
button.innerText = text;
}, 800);
});
}
function addSectionLinksToSidebar() {
const postSidebar = document.querySelector(".post-sidebar");
const sectionLinks = Array.from(document.querySelectorAll(".post a[id]"));
if (sectionLinks.length === 0) return;
if (!postSidebar) return;
const link = window.location.href.split(".html")[0] + ".html";
const listItems = sectionLinks
.map((v) => {
const url = `${link}#${v.id}`;
v.onclick = () => copyToClipboard(v, url);
const item = `
${v.innerText}
`;
return item;
})
.join("");
const section = document.createElement("div");
section.id = "sections";
section.className = "post-sidebar-item post-sidebar-labels";
section.innerHTML = `Sections
`;
const sharing = postSidebar.children[0];
sharing.insertAdjacentElement("afterend", section);
}
updatePostViews();
addSectionLinksToSidebar();
addBackToTopButton();
addImageModal();