blob: f16974e8e48b0f31a7f2a082acb4b4c7cae45f08 [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
Adrià Vilanova Martínezf93656e2022-01-28 10:54:28 +01005const kLoadMoreButtons = [
6 {
7 feature: 'thread',
8 buttonSelectors: [
9 '.thread-all-replies__load-more-button',
10 '.scTailwindThreadMorebuttonload-more .scTailwindThreadMorebuttonbutton',
11 ],
12 },
13 {
14 feature: 'threadall',
15 buttonSelectors: [
16 '.thread-all-replies__load-all-button',
17 '.scTailwindThreadMorebuttonload-all .scTailwindThreadMorebuttonbutton',
18 ],
19 }
20];
21
avm9996336b8dbc2020-09-01 21:16:19 +020022var intersectionObserver;
avm99963cbea3142019-03-28 00:48:15 +010023
avm9996336b8dbc2020-09-01 21:16:19 +020024function intersectionCallback(entries, observer) {
25 entries.forEach(entry => {
26 if (entry.isIntersecting) {
27 entry.target.click();
avm99963cbea3142019-03-28 00:48:15 +010028 }
29 });
avm9996336b8dbc2020-09-01 21:16:19 +020030};
31
32var intersectionOptions = {
33 threshold: 1.0,
34};
35
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020036getOptions(null).then(options => {
avm9996336b8dbc2020-09-01 21:16:19 +020037 var redirectLink = document.querySelector('.community-console');
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020038 if (options.redirect && redirectLink !== null) {
avm99963dda2b042021-03-16 23:59:08 +010039 var redirectUrl = redirectLink.href;
40
41 var searchParams = new URLSearchParams(location.search);
42 if (searchParams.has('msgid') && searchParams.get('msgid') !== '' &&
43 CCThreadWithoutMessage.test(redirectUrl))
44 redirectUrl +=
45 '/message/' + encodeURIComponent(searchParams.get('msgid'));
46
47 window.location = redirectUrl;
avm9996336b8dbc2020-09-01 21:16:19 +020048 } else {
Adrià Vilanova Martínezf93656e2022-01-28 10:54:28 +010049 for (const entry of kLoadMoreButtons)
50 if (options[entry.feature])
51 for (const selector of entry.buttonSelectors) {
52 let button = document.querySelector(selector);
53 if (button !== null) {
54 intersectionObserver = new IntersectionObserver(
55 intersectionCallback, intersectionOptions);
56 intersectionObserver.observe(button);
57 }
58 }
avm9996336b8dbc2020-09-01 21:16:19 +020059 }
60});