blob: 84cb1812fcdfb933b59d19932664967e6773cade [file] [log] [blame]
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +02001import {getOptions} from '../common/optionsUtils.js';
2
avm99963dda2b042021-03-16 23:59:08 +01003var CCThreadWithoutMessage = /forum\/[0-9]*\/thread\/[0-9]*$/;
4
avm9996336b8dbc2020-09-01 21:16:19 +02005var intersectionObserver;
avm99963cbea3142019-03-28 00:48:15 +01006
avm9996336b8dbc2020-09-01 21:16:19 +02007function intersectionCallback(entries, observer) {
8 entries.forEach(entry => {
9 if (entry.isIntersecting) {
10 entry.target.click();
avm99963cbea3142019-03-28 00:48:15 +010011 }
12 });
avm9996336b8dbc2020-09-01 21:16:19 +020013};
14
15var intersectionOptions = {
16 threshold: 1.0,
17};
18
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020019getOptions(null).then(options => {
avm9996336b8dbc2020-09-01 21:16:19 +020020 var redirectLink = document.querySelector('.community-console');
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020021 if (options.redirect && redirectLink !== null) {
avm99963dda2b042021-03-16 23:59:08 +010022 var redirectUrl = redirectLink.href;
23
24 var searchParams = new URLSearchParams(location.search);
25 if (searchParams.has('msgid') && searchParams.get('msgid') !== '' &&
26 CCThreadWithoutMessage.test(redirectUrl))
27 redirectUrl +=
28 '/message/' + encodeURIComponent(searchParams.get('msgid'));
29
30 window.location = redirectUrl;
avm9996336b8dbc2020-09-01 21:16:19 +020031 } else {
32 var button =
33 document.querySelector('.thread-all-replies__load-more-button');
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020034 if (options.thread && button !== null) {
avm9996336b8dbc2020-09-01 21:16:19 +020035 intersectionObserver =
36 new IntersectionObserver(intersectionCallback, intersectionOptions);
37 intersectionObserver.observe(button);
38 }
39 var allbutton =
40 document.querySelector('.thread-all-replies__load-all-button');
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020041 if (options.threadall && button !== null) {
avm9996336b8dbc2020-09-01 21:16:19 +020042 intersectionObserver =
43 new IntersectionObserver(intersectionCallback, intersectionOptions);
44 intersectionObserver.observe(allbutton);
45 }
46 }
47});