Exclude matches with manifest.json instead of JS
Some wrong matches were being excluded with Javascript code testing the
location.href value. This commit deletes these Javascript tests and
implements them directly in the manifest.gjson file by placing them
inside the exclude_matches argument.
Change-Id: Idba4086b7061eaea837d7c7a3e3564c144535e42
diff --git a/src/content_scripts/thread_inject.js b/src/content_scripts/thread_inject.js
index 90eb421..984774e 100644
--- a/src/content_scripts/thread_inject.js
+++ b/src/content_scripts/thread_inject.js
@@ -1,45 +1,35 @@
-var CCRegex = /^https:\/\/support\.google\.com\/s\/community/;
-if (!CCRegex.test(location.href)) {
- var intersectionObserver;
+var intersectionObserver;
- function intersectionCallback(entries, observer) {
- entries.forEach(entry => {
- if (entry.isIntersecting) {
- entry.target.click();
- }
- });
- };
-
- var intersectionOptions = {
- threshold: 1.0,
- };
-
- chrome.storage.sync.get(null, function(items) {
- var path = document.location.pathname.split('/');
- if (path[path.length - 1] == 'new' ||
- (path.length > 1 && path[path.length - 1] == '' &&
- path[path.length - 2] == 'new')) {
- return;
- }
-
- var redirectLink = document.querySelector('.community-console');
- if (items.redirect && redirectLink !== null) {
- window.location = redirectLink.href;
- } else {
- var button =
- document.querySelector('.thread-all-replies__load-more-button');
- if (items.thread && button !== null) {
- intersectionObserver =
- new IntersectionObserver(intersectionCallback, intersectionOptions);
- intersectionObserver.observe(button);
- }
- var allbutton =
- document.querySelector('.thread-all-replies__load-all-button');
- if (items.threadall && button !== null) {
- intersectionObserver =
- new IntersectionObserver(intersectionCallback, intersectionOptions);
- intersectionObserver.observe(allbutton);
- }
+function intersectionCallback(entries, observer) {
+ entries.forEach(entry => {
+ if (entry.isIntersecting) {
+ entry.target.click();
}
});
-}
+};
+
+var intersectionOptions = {
+ threshold: 1.0,
+};
+
+chrome.storage.sync.get(null, function(items) {
+ var redirectLink = document.querySelector('.community-console');
+ if (items.redirect && redirectLink !== null) {
+ window.location = redirectLink.href;
+ } else {
+ var button =
+ document.querySelector('.thread-all-replies__load-more-button');
+ if (items.thread && button !== null) {
+ intersectionObserver =
+ new IntersectionObserver(intersectionCallback, intersectionOptions);
+ intersectionObserver.observe(button);
+ }
+ var allbutton =
+ document.querySelector('.thread-all-replies__load-all-button');
+ if (items.threadall && button !== null) {
+ intersectionObserver =
+ new IntersectionObserver(intersectionCallback, intersectionOptions);
+ intersectionObserver.observe(allbutton);
+ }
+ }
+});
diff --git a/templates/manifest.gjson b/templates/manifest.gjson
index 97deaba..5fd7fff 100644
--- a/templates/manifest.gjson
+++ b/templates/manifest.gjson
@@ -26,11 +26,13 @@
},
{
"matches": ["https://support.google.com/*/thread/*"],
+ "exclude_matches": ["https://support.google.com/s/community*", "https://support.google.com/*/thread/new*"],
"js": ["common/content_scripts.js", "content_scripts/thread_inject.js"],
"run_at": "document_end"
},
{
"matches": ["https://support.google.com/s/community*", "https://support.google.com/*/thread/*"],
+ "exclude_matches": ["https://support.google.com/*/thread/new*"],
"js": ["common/content_scripts.js", "content_scripts/profileindicator_inject.js"]
},
{