Adrià Vilanova Martínez | b523be9 | 2024-05-25 19:14:19 +0200 | [diff] [blame] | 1 | import {getOptions} from '../common/options/optionsUtils.js'; |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 2 | |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 3 | var intersectionObserver; |
| 4 | |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 5 | function intersectionCallback(entries, observer) { |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 6 | entries.forEach(entry => { |
| 7 | if (entry.isIntersecting) { |
| 8 | entry.target.click(); |
| 9 | } |
| 10 | }); |
| 11 | }; |
| 12 | |
| 13 | var intersectionOptions = { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 14 | threshold: 1.0, |
| 15 | }; |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 16 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 17 | getOptions('list').then(options => { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 18 | var button = document.querySelector('.thread-list-threads__load-more-button'); |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 19 | if (options.list && button !== null) { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 20 | intersectionObserver = |
| 21 | new IntersectionObserver(intersectionCallback, intersectionOptions); |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 22 | intersectionObserver.observe(button); |
Adrià Vilanova Martínez | 2092c5b | 2021-09-24 23:40:31 +0200 | [diff] [blame] | 23 | |
| 24 | // On a best-effort basis, move the "ask community" card before the "load |
| 25 | // more" button, if both exist. |
| 26 | let buttonContainer = document.querySelector( |
| 27 | '.thread-list__threads > .thread-list-threads__load-more-container'); |
| 28 | let askCard = |
| 29 | document.querySelector('.thread-list__threads > .ask-community-card'); |
| 30 | if (buttonContainer !== null && askCard !== null) { |
| 31 | let threadList = document.querySelector('.thread-list__threads'); |
| 32 | threadList.insertBefore(askCard, buttonContainer); |
| 33 | } |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 34 | } |
| 35 | }); |