blob: 110b5c45a1208d0cc2d5ff55a862426a730fa099 [file] [log] [blame]
avm99963dda2b042021-03-16 23:59:08 +01001var CCThreadWithoutMessage = /forum\/[0-9]*\/thread\/[0-9]*$/;
2
avm9996336b8dbc2020-09-01 21:16:19 +02003var intersectionObserver;
avm99963cbea3142019-03-28 00:48:15 +01004
avm9996336b8dbc2020-09-01 21:16:19 +02005function intersectionCallback(entries, observer) {
6 entries.forEach(entry => {
7 if (entry.isIntersecting) {
8 entry.target.click();
avm99963cbea3142019-03-28 00:48:15 +01009 }
10 });
avm9996336b8dbc2020-09-01 21:16:19 +020011};
12
13var intersectionOptions = {
14 threshold: 1.0,
15};
16
17chrome.storage.sync.get(null, function(items) {
18 var redirectLink = document.querySelector('.community-console');
19 if (items.redirect && redirectLink !== null) {
avm99963dda2b042021-03-16 23:59:08 +010020 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;
avm9996336b8dbc2020-09-01 21:16:19 +020029 } 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});