blob: 5ad2a81354975a208a70eea8db56a414daac87a0 [file] [log] [blame]
Adrià Vilanova Martínezc0a0abc2022-01-28 11:06:02 +01001import {injectStylesheet} from '../common/contentScriptsUtils.js';
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +02002import {getOptions} from '../common/optionsUtils.js';
3
avm99963dda2b042021-03-16 23:59:08 +01004var CCThreadWithoutMessage = /forum\/[0-9]*\/thread\/[0-9]*$/;
5
Adrià Vilanova Martínezf93656e2022-01-28 10:54:28 +01006const kLoadMoreButtons = [
7 {
8 feature: 'thread',
9 buttonSelectors: [
10 '.thread-all-replies__load-more-button',
11 '.scTailwindThreadMorebuttonload-more .scTailwindThreadMorebuttonbutton',
Adrià Vilanova Martínez88854972022-08-28 11:57:12 +020012 '.scTailwindThreadMessagegapload-more .scTailwindThreadMessagegapbutton',
Adrià Vilanova Martínezf93656e2022-01-28 10:54:28 +010013 ],
14 },
15 {
16 feature: 'threadall',
17 buttonSelectors: [
18 '.thread-all-replies__load-all-button',
19 '.scTailwindThreadMorebuttonload-all .scTailwindThreadMorebuttonbutton',
Adrià Vilanova Martínez88854972022-08-28 11:57:12 +020020 '.scTailwindThreadMessagegapload-all .scTailwindThreadMessagegapbutton',
Adrià Vilanova Martínezf93656e2022-01-28 10:54:28 +010021 ],
22 }
23];
24
avm9996336b8dbc2020-09-01 21:16:19 +020025var intersectionObserver;
avm99963cbea3142019-03-28 00:48:15 +010026
avm9996336b8dbc2020-09-01 21:16:19 +020027function intersectionCallback(entries, observer) {
28 entries.forEach(entry => {
29 if (entry.isIntersecting) {
30 entry.target.click();
avm99963cbea3142019-03-28 00:48:15 +010031 }
32 });
avm9996336b8dbc2020-09-01 21:16:19 +020033};
34
35var intersectionOptions = {
36 threshold: 1.0,
37};
38
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020039getOptions(null).then(options => {
avm9996336b8dbc2020-09-01 21:16:19 +020040 var redirectLink = document.querySelector('.community-console');
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020041 if (options.redirect && redirectLink !== null) {
avm99963dda2b042021-03-16 23:59:08 +010042 var redirectUrl = redirectLink.href;
43
44 var searchParams = new URLSearchParams(location.search);
45 if (searchParams.has('msgid') && searchParams.get('msgid') !== '' &&
46 CCThreadWithoutMessage.test(redirectUrl))
47 redirectUrl +=
48 '/message/' + encodeURIComponent(searchParams.get('msgid'));
49
50 window.location = redirectUrl;
avm9996336b8dbc2020-09-01 21:16:19 +020051 } else {
Adrià Vilanova Martínezf93656e2022-01-28 10:54:28 +010052 for (const entry of kLoadMoreButtons)
53 if (options[entry.feature])
54 for (const selector of entry.buttonSelectors) {
55 let button = document.querySelector(selector);
56 if (button !== null) {
57 intersectionObserver = new IntersectionObserver(
58 intersectionCallback, intersectionOptions);
59 intersectionObserver.observe(button);
60 }
61 }
Adrià Vilanova Martínezc0a0abc2022-01-28 11:06:02 +010062
63 if (options.imagemaxheight)
64 injectStylesheet(chrome.runtime.getURL('css/image_max_height.css'));
avm9996336b8dbc2020-09-01 21:16:19 +020065 }
66});