avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 1 | var intersectionObserver; |
| 2 | |
| 3 | function intersectionCallback(entries, observer) { |
| 4 | entries.forEach(entry => { |
| 5 | if (entry.isIntersecting) { |
| 6 | entry.target.click(); |
| 7 | } |
| 8 | }); |
| 9 | }; |
| 10 | |
| 11 | var intersectionOptions = { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 12 | threshold: 1.0, |
| 13 | }; |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 14 | |
| 15 | chrome.storage.sync.get(null, function(items) { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 16 | var path = document.location.pathname.split('/'); |
| 17 | if (path[path.length - 1] == 'new' || |
| 18 | (path.length > 1 && path[path.length - 1] == '' && |
| 19 | path[path.length - 2] == 'new')) { |
avm99963 | 7db655f | 2020-08-18 11:44:31 +0200 | [diff] [blame] | 20 | return; |
| 21 | } |
| 22 | |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 23 | var redirectLink = document.querySelector('.community-console'); |
avm99963 | 134f1ef | 2019-03-30 19:05:27 +0100 | [diff] [blame] | 24 | if (items.redirect && redirectLink !== null) { |
| 25 | window.location = redirectLink.href; |
| 26 | } else { |
avm99963 | 7db655f | 2020-08-18 11:44:31 +0200 | [diff] [blame] | 27 | var button = |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 28 | document.querySelector('.thread-all-replies__load-more-button'); |
avm99963 | 134f1ef | 2019-03-30 19:05:27 +0100 | [diff] [blame] | 29 | if (items.thread && button !== null) { |
avm99963 | 7db655f | 2020-08-18 11:44:31 +0200 | [diff] [blame] | 30 | intersectionObserver = |
| 31 | new IntersectionObserver(intersectionCallback, intersectionOptions); |
avm99963 | 134f1ef | 2019-03-30 19:05:27 +0100 | [diff] [blame] | 32 | intersectionObserver.observe(button); |
| 33 | } |
avm99963 | 7db655f | 2020-08-18 11:44:31 +0200 | [diff] [blame] | 34 | var allbutton = |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 35 | document.querySelector('.thread-all-replies__load-all-button'); |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 36 | if (items.threadall && button !== null) { |
avm99963 | 7db655f | 2020-08-18 11:44:31 +0200 | [diff] [blame] | 37 | intersectionObserver = |
| 38 | new IntersectionObserver(intersectionCallback, intersectionOptions); |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 39 | intersectionObserver.observe(allbutton); |
| 40 | } |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 41 | } |
| 42 | }); |