Add basic HTML parsing

This commit is contained in:
Saphire committed 2022-02-19 23:51:04 +07:00
1 parent 387909b0c6
commit a7250ceacf
14 files changed
+627 -100

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
class VisitAnalytics {
observer;
constructor() {
window.plausible = window.plausible || function () { (window.plausible.q = window.plausible.q || []).push(arguments); };
if (document.readyState == "interactive")
this.init()
else
document.addEventListener("DOMContentLoaded", () => this.init(), false);
}
init() {
let options = {
root: null,
rootMargin: "0px",
threshold: 1.0
};
this.observer = new IntersectionObserver((entries, observer) => this.handleIntersect(entries, observer), options);
var all = document.querySelectorAll(".chapter-announce");
all.forEach(elem => this.observer.observe(elem));
this.observer.observe(document.querySelector("footer"));
console.log("Intersection observer ready");
}
handleIntersect(entries: IntersectionObserverEntry[], observer: IntersectionObserver) {
entries.filter(e => e.isIntersecting).forEach(e => {
if (e.target.className == "chapter-announce" && !e.target.nextElementSibling.querySelector("img").complete)
return;
window.plausible("landmark", {props: {id: e.target.id ? e.target.id : e.target.tagName}});
observer.unobserve(e.target);
console.log("Reached landmark " + e.target.id ? e.target.id : e.target.tagName);
}
);
}
}
new VisitAnalytics();