blob: 2bc6f15cc9ab8cf5a5c573a7831f6fddd32e32c1 [file] [log] [blame]
avm99963cbea3142019-03-28 00:48:15 +01001var mutationObserver, intersectionObserver, options;
2
avm99963847ee632019-03-27 00:57:44 +01003function mutationCallback(mutationList, observer) {
4 mutationList.forEach((mutation) => {
5 if (mutation.type == "childList") {
6 mutation.addedNodes.forEach(function (node) {
avm99963cbea3142019-03-28 00:48:15 +01007 if (options.list && (typeof node.classList !== "undefined") && node.classList.contains("view-more-button-container")) {
avm99963847ee632019-03-27 00:57:44 +01008 intersectionObserver.observe(node.querySelector(".view-more-button"));
9 }
Nico Sinisterra4ae1c572019-03-27 12:57:13 -030010
avm99963cbea3142019-03-28 00:48:15 +010011 if (options.thread && (typeof node.classList !== "undefined") && node.classList.contains("load-more-bar")) {
Nico Sinisterra4ae1c572019-03-27 12:57:13 -030012 intersectionObserver.observe(node.querySelector(".load-more-button"));
13 }
avm99963847ee632019-03-27 00:57:44 +010014 });
15 }
16 });
17}
18
19function intersectionCallback(entries, observer) {
20 entries.forEach(entry => {
21 if (entry.isIntersecting) {
22 entry.target.click();
23 }
24 });
25};
26
27var observerOptions = {
28 childList: true,
29 attributes: true,
30 subtree: true
31}
32
avm99963847ee632019-03-27 00:57:44 +010033var intersectionOptions = {
34 root: document.querySelector('.scrollable-content'),
35 rootMargin: '0px',
36 threshold: 1.0
37}
38
avm99963cbea3142019-03-28 00:48:15 +010039chrome.storage.sync.get(null, function(items) {
40 options = items;
41
42 mutationObserver = new MutationObserver(mutationCallback);
43 mutationObserver.observe(document.querySelector(".scrollable-content"), observerOptions);
44
45 intersectionObserver = new IntersectionObserver(intersectionCallback, intersectionOptions);
46});