avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 1 | var mutationObserver, intersectionObserver, options; |
| 2 | |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 3 | function mutationCallback(mutationList, observer) { |
| 4 | mutationList.forEach((mutation) => { |
| 5 | if (mutation.type == "childList") { |
| 6 | mutation.addedNodes.forEach(function (node) { |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 7 | if (options.list && (typeof node.classList !== "undefined") && node.classList.contains("view-more-button-container")) { |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 8 | intersectionObserver.observe(node.querySelector(".view-more-button")); |
| 9 | } |
Nico Sinisterra | 4ae1c57 | 2019-03-27 12:57:13 -0300 | [diff] [blame] | 10 | |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 11 | if (options.thread && (typeof node.classList !== "undefined") && node.classList.contains("load-more-bar")) { |
Nico Sinisterra | 4ae1c57 | 2019-03-27 12:57:13 -0300 | [diff] [blame] | 12 | intersectionObserver.observe(node.querySelector(".load-more-button")); |
| 13 | } |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 14 | }); |
| 15 | } |
| 16 | }); |
| 17 | } |
| 18 | |
| 19 | function intersectionCallback(entries, observer) { |
| 20 | entries.forEach(entry => { |
| 21 | if (entry.isIntersecting) { |
| 22 | entry.target.click(); |
| 23 | } |
| 24 | }); |
| 25 | }; |
| 26 | |
| 27 | var observerOptions = { |
| 28 | childList: true, |
| 29 | attributes: true, |
| 30 | subtree: true |
| 31 | } |
| 32 | |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 33 | var intersectionOptions = { |
| 34 | root: document.querySelector('.scrollable-content'), |
| 35 | rootMargin: '0px', |
| 36 | threshold: 1.0 |
| 37 | } |
| 38 | |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 39 | chrome.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 | }); |