blob: 706277fd8c03508f5d81b757bf88cd1abdcf0c0d [file] [log] [blame]
avm99963a92652e2020-08-31 22:05:10 +02001var CCRegex = /^https:\/\/support\.google\.com\/s\/community/;
2if (!CCRegex.test(location.href)) {
3 var intersectionObserver;
avm99963cbea3142019-03-28 00:48:15 +01004
avm99963a92652e2020-08-31 22:05:10 +02005 function intersectionCallback(entries, observer) {
6 entries.forEach(entry => {
7 if (entry.isIntersecting) {
8 entry.target.click();
9 }
10 });
11 };
12
13 var intersectionOptions = {
14 threshold: 1.0,
15 };
16
17 chrome.storage.sync.get(null, function(items) {
18 var path = document.location.pathname.split('/');
19 if (path[path.length - 1] == 'new' ||
20 (path.length > 1 && path[path.length - 1] == '' &&
21 path[path.length - 2] == 'new')) {
22 return;
23 }
24
25 var redirectLink = document.querySelector('.community-console');
26 if (items.redirect && redirectLink !== null) {
27 window.location = redirectLink.href;
28 } else {
29 var button =
30 document.querySelector('.thread-all-replies__load-more-button');
31 if (items.thread && button !== null) {
32 intersectionObserver =
33 new IntersectionObserver(intersectionCallback, intersectionOptions);
34 intersectionObserver.observe(button);
35 }
36 var allbutton =
37 document.querySelector('.thread-all-replies__load-all-button');
38 if (items.threadall && button !== null) {
39 intersectionObserver =
40 new IntersectionObserver(intersectionCallback, intersectionOptions);
41 intersectionObserver.observe(allbutton);
42 }
43
44 if (items.profileindicator) {
45 injectScript(
46 chrome.runtime.getURL('injections/profileindicator_inject.js'));
47 injectStylesheet(
48 chrome.runtime.getURL('injections/profileindicator_inject.css'));
49
50 // In order to pass i18n strings to the injected script, which doesn't
51 // have access to the chrome.i18n API.
52 window.addEventListener('geti18nString', evt => {
53 var request = evt.detail;
54 var response = {
55 string: chrome.i18n.getMessage(request.msg),
56 requestId: request.id
57 };
58 window.dispatchEvent(
59 new CustomEvent('sendi18nString', {detail: response}));
60 });
61 }
avm99963cbea3142019-03-28 00:48:15 +010062 }
63 });
avm99963a92652e2020-08-31 22:05:10 +020064}