Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 1 | import {getOptions} from '../common/optionsUtils.js'; |
| 2 | |
avm99963 | dda2b04 | 2021-03-16 23:59:08 +0100 | [diff] [blame] | 3 | var CCThreadWithoutMessage = /forum\/[0-9]*\/thread\/[0-9]*$/; |
| 4 | |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 5 | var intersectionObserver; |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 6 | |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 7 | function intersectionCallback(entries, observer) { |
| 8 | entries.forEach(entry => { |
| 9 | if (entry.isIntersecting) { |
| 10 | entry.target.click(); |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 11 | } |
| 12 | }); |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 13 | }; |
| 14 | |
| 15 | var intersectionOptions = { |
| 16 | threshold: 1.0, |
| 17 | }; |
| 18 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 19 | getOptions(null).then(options => { |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 20 | var redirectLink = document.querySelector('.community-console'); |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 21 | if (options.redirect && redirectLink !== null) { |
avm99963 | dda2b04 | 2021-03-16 23:59:08 +0100 | [diff] [blame] | 22 | var redirectUrl = redirectLink.href; |
| 23 | |
| 24 | var searchParams = new URLSearchParams(location.search); |
| 25 | if (searchParams.has('msgid') && searchParams.get('msgid') !== '' && |
| 26 | CCThreadWithoutMessage.test(redirectUrl)) |
| 27 | redirectUrl += |
| 28 | '/message/' + encodeURIComponent(searchParams.get('msgid')); |
| 29 | |
| 30 | window.location = redirectUrl; |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 31 | } else { |
| 32 | var button = |
| 33 | document.querySelector('.thread-all-replies__load-more-button'); |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 34 | if (options.thread && button !== null) { |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 35 | intersectionObserver = |
| 36 | new IntersectionObserver(intersectionCallback, intersectionOptions); |
| 37 | intersectionObserver.observe(button); |
| 38 | } |
| 39 | var allbutton = |
| 40 | document.querySelector('.thread-all-replies__load-all-button'); |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 41 | if (options.threadall && button !== null) { |
avm99963 | 36b8dbc | 2020-09-01 21:16:19 +0200 | [diff] [blame] | 42 | intersectionObserver = |
| 43 | new IntersectionObserver(intersectionCallback, intersectionOptions); |
| 44 | intersectionObserver.observe(allbutton); |
| 45 | } |
| 46 | } |
| 47 | }); |