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', |
| 12 | ], |
| 13 | }, |
| 14 | { |
| 15 | feature: 'threadall', |
| 16 | buttonSelectors: [ |
| 17 | '.thread-all-replies__load-all-button', |
| 18 | '.scTailwindThreadMorebuttonload-all .scTailwindThreadMorebuttonbutton', |
| 19 | ], |
| 20 | } |
| 21 | ]; |
| 22 | |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 23 | var intersectionObserver; |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 24 | |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 25 | function intersectionCallback(entries, observer) { |
| 26 | entries.forEach(entry => { |
| 27 | if (entry.isIntersecting) { |
| 28 | entry.target.click(); |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 29 | } |
| 30 | }); |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | var intersectionOptions = { |
| 34 | threshold: 1.0, |
| 35 | }; |
| 36 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 37 | getOptions(null).then(options => { |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 38 | var redirectLink = document.querySelector('.community-console'); |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 39 | if (options.redirect && redirectLink !== null) { |
avm99963 | dda2b04 | 2021-03-16 23:59:08 +0100 | [diff] [blame] | 40 | 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; |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 49 | } else { |
Adrià Vilanova Martínez | f93656e | 2022-01-28 10:54:28 +0100 | [diff] [blame] | 50 | 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ínez | c0a0abc | 2022-01-28 11:06:02 +0100 | [diff] [blame] | 60 | |
| 61 | if (options.imagemaxheight) |
| 62 | injectStylesheet(chrome.runtime.getURL('css/image_max_height.css')); |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 63 | } |
| 64 | }); |