blob: d03976b9342d4b6443d5b8fc923c570902100613 [file] [log] [blame]
Adrià Vilanova Martínezb523be92024-05-25 19:14:19 +02001import {getOptions} from '../common/options/optionsUtils.js';
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +02002
avm99963cbea3142019-03-28 00:48:15 +01003var intersectionObserver;
4
avm99963847ee632019-03-27 00:57:44 +01005function intersectionCallback(entries, observer) {
avm99963847ee632019-03-27 00:57:44 +01006 entries.forEach(entry => {
7 if (entry.isIntersecting) {
8 entry.target.click();
9 }
10 });
11};
12
13var intersectionOptions = {
avm99963b69eb3d2020-08-20 02:03:44 +020014 threshold: 1.0,
15};
avm99963847ee632019-03-27 00:57:44 +010016
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020017getOptions('list').then(options => {
avm99963b69eb3d2020-08-20 02:03:44 +020018 var button = document.querySelector('.thread-list-threads__load-more-button');
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020019 if (options.list && button !== null) {
avm99963b69eb3d2020-08-20 02:03:44 +020020 intersectionObserver =
21 new IntersectionObserver(intersectionCallback, intersectionOptions);
avm99963cbea3142019-03-28 00:48:15 +010022 intersectionObserver.observe(button);
Adrià Vilanova Martínez2092c5b2021-09-24 23:40:31 +020023
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 }
avm99963cbea3142019-03-28 00:48:15 +010034 }
35});