blob: fb251b913a21baf960868120f1d5e38712dd3374 [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',
12 ],
13 },
14 {
15 feature: 'threadall',
16 buttonSelectors: [
17 '.thread-all-replies__load-all-button',
18 '.scTailwindThreadMorebuttonload-all .scTailwindThreadMorebuttonbutton',
19 ],
20 }
21];
22
avm9996336b8dbc2020-09-01 21:16:19 +020023var intersectionObserver;
avm99963cbea3142019-03-28 00:48:15 +010024
avm9996336b8dbc2020-09-01 21:16:19 +020025function intersectionCallback(entries, observer) {
26 entries.forEach(entry => {
27 if (entry.isIntersecting) {
28 entry.target.click();
avm99963cbea3142019-03-28 00:48:15 +010029 }
30 });
avm9996336b8dbc2020-09-01 21:16:19 +020031};
32
33var intersectionOptions = {
34 threshold: 1.0,
35};
36
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020037getOptions(null).then(options => {
avm9996336b8dbc2020-09-01 21:16:19 +020038 var redirectLink = document.querySelector('.community-console');
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020039 if (options.redirect && redirectLink !== null) {
avm99963dda2b042021-03-16 23:59:08 +010040 var redirectUrl = redirectLink.href;
41
42 var searchParams = new URLSearchParams(location.search);
43 if (searchParams.has('msgid') && searchParams.get('msgid') !== '' &&
44 CCThreadWithoutMessage.test(redirectUrl))
45 redirectUrl +=
46 '/message/' + encodeURIComponent(searchParams.get('msgid'));
47
48 window.location = redirectUrl;
avm9996336b8dbc2020-09-01 21:16:19 +020049 } else {
Adrià Vilanova Martínezf93656e2022-01-28 10:54:28 +010050 for (const entry of kLoadMoreButtons)
51 if (options[entry.feature])
52 for (const selector of entry.buttonSelectors) {
53 let button = document.querySelector(selector);
54 if (button !== null) {
55 intersectionObserver = new IntersectionObserver(
56 intersectionCallback, intersectionOptions);
57 intersectionObserver.observe(button);
58 }
59 }
Adrià Vilanova Martínezc0a0abc2022-01-28 11:06:02 +010060
61 if (options.imagemaxheight)
62 injectStylesheet(chrome.runtime.getURL('css/image_max_height.css'));
avm9996336b8dbc2020-09-01 21:16:19 +020063 }
64});