blob: b94f4050b9bf4eaad936bae7c74191dd8085eee5 [file] [log] [blame]
avm99963cbea3142019-03-28 00:48:15 +01001var intersectionObserver;
2
3function intersectionCallback(entries, observer) {
4 entries.forEach(entry => {
5 if (entry.isIntersecting) {
6 entry.target.click();
7 }
8 });
9};
10
11var intersectionOptions = {
avm99963b69eb3d2020-08-20 02:03:44 +020012 threshold: 1.0,
13};
avm99963cbea3142019-03-28 00:48:15 +010014
15chrome.storage.sync.get(null, function(items) {
avm99963b69eb3d2020-08-20 02:03:44 +020016 var path = document.location.pathname.split('/');
17 if (path[path.length - 1] == 'new' ||
18 (path.length > 1 && path[path.length - 1] == '' &&
19 path[path.length - 2] == 'new')) {
avm999637db655f2020-08-18 11:44:31 +020020 return;
21 }
22
avm99963b69eb3d2020-08-20 02:03:44 +020023 var redirectLink = document.querySelector('.community-console');
avm99963134f1ef2019-03-30 19:05:27 +010024 if (items.redirect && redirectLink !== null) {
25 window.location = redirectLink.href;
26 } else {
avm999637db655f2020-08-18 11:44:31 +020027 var button =
avm99963b69eb3d2020-08-20 02:03:44 +020028 document.querySelector('.thread-all-replies__load-more-button');
avm99963134f1ef2019-03-30 19:05:27 +010029 if (items.thread && button !== null) {
avm999637db655f2020-08-18 11:44:31 +020030 intersectionObserver =
31 new IntersectionObserver(intersectionCallback, intersectionOptions);
avm99963134f1ef2019-03-30 19:05:27 +010032 intersectionObserver.observe(button);
33 }
avm999637db655f2020-08-18 11:44:31 +020034 var allbutton =
avm99963b69eb3d2020-08-20 02:03:44 +020035 document.querySelector('.thread-all-replies__load-all-button');
avm999636d9c5fe2019-06-04 00:35:53 +020036 if (items.threadall && button !== null) {
avm999637db655f2020-08-18 11:44:31 +020037 intersectionObserver =
38 new IntersectionObserver(intersectionCallback, intersectionOptions);
avm999636d9c5fe2019-06-04 00:35:53 +020039 intersectionObserver.observe(allbutton);
40 }
avm99963cbea3142019-03-28 00:48:15 +010041 }
42});