Adrià Vilanova Martínez | c0a0abc | 2022-01-28 11:06:02 +0100 | [diff] [blame] | 1 | import {injectStylesheet} from '../common/contentScriptsUtils.js'; |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 2 | import {getOptions} from '../common/optionsUtils.js'; |
| 3 | |
avm99963 | dda2b04 | 2021-03-16 23:59:08 +0100 | [diff] [blame] | 4 | var CCThreadWithoutMessage = /forum\/[0-9]*\/thread\/[0-9]*$/; |
| 5 | |
Adrià Vilanova Martínez | f93656e | 2022-01-28 10:54:28 +0100 | [diff] [blame] | 6 | const kLoadMoreButtons = [ |
| 7 | { |
| 8 | feature: 'thread', |
| 9 | buttonSelectors: [ |
| 10 | '.thread-all-replies__load-more-button', |
| 11 | '.scTailwindThreadMorebuttonload-more .scTailwindThreadMorebuttonbutton', |
Adrià Vilanova Martínez | 8885497 | 2022-08-28 11:57:12 +0200 | [diff] [blame] | 12 | '.scTailwindThreadMessagegapload-more .scTailwindThreadMessagegapbutton', |
Adrià Vilanova Martínez | f93656e | 2022-01-28 10:54:28 +0100 | [diff] [blame] | 13 | ], |
| 14 | }, |
| 15 | { |
| 16 | feature: 'threadall', |
| 17 | buttonSelectors: [ |
| 18 | '.thread-all-replies__load-all-button', |
| 19 | '.scTailwindThreadMorebuttonload-all .scTailwindThreadMorebuttonbutton', |
Adrià Vilanova Martínez | 8885497 | 2022-08-28 11:57:12 +0200 | [diff] [blame] | 20 | '.scTailwindThreadMessagegapload-all .scTailwindThreadMessagegapbutton', |
Adrià Vilanova Martínez | f93656e | 2022-01-28 10:54:28 +0100 | [diff] [blame] | 21 | ], |
| 22 | } |
| 23 | ]; |
| 24 | |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 25 | var intersectionObserver; |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 26 | |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 27 | function intersectionCallback(entries, observer) { |
| 28 | entries.forEach(entry => { |
| 29 | if (entry.isIntersecting) { |
| 30 | entry.target.click(); |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 31 | } |
| 32 | }); |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | var intersectionOptions = { |
| 36 | threshold: 1.0, |
| 37 | }; |
| 38 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 39 | getOptions(null).then(options => { |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 40 | var redirectLink = document.querySelector('.community-console'); |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 41 | if (options.redirect && redirectLink !== null) { |
avm99963 | dda2b04 | 2021-03-16 23:59:08 +0100 | [diff] [blame] | 42 | 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; |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 51 | } else { |
Adrià Vilanova Martínez | f93656e | 2022-01-28 10:54:28 +0100 | [diff] [blame] | 52 | 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ínez | c0a0abc | 2022-01-28 11:06:02 +0100 | [diff] [blame] | 62 | |
| 63 | if (options.imagemaxheight) |
| 64 | injectStylesheet(chrome.runtime.getURL('css/image_max_height.css')); |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 65 | } |
| 66 | }); |