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