Skip to content

Commit 54c2617

Browse files
committed
Optimized and restructured latest changes
1 parent 51dd4f1 commit 54c2617

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

background.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const canceledRequests = {};
5454
const tabsWaitingToLoad = {};
5555
const googleHostREs = [];
5656
const youtubeHostREs = [];
57+
const searchpagePathREs = [];
5758

5859
async function isMACAddonEnabled () {
5960
try {
@@ -156,6 +157,9 @@ function generateGoogleHostREs () {
156157
for (let youtubeDomain of YOUTUBE_DOMAINS) {
157158
youtubeHostREs.push(new RegExp(`^(.*\\.)?${youtubeDomain}$`));
158159
}
160+
for (let searchpagePath of SEARCHPAGE_PATHS) {
161+
searchpagePathREs.push(new RegExp(`^${searchpagePath}(.*)`));
162+
}
159163
}
160164

161165
async function loadExtensionSettings () {
@@ -241,25 +245,27 @@ function isGoogleURL (url) {
241245
const parsedUrl = new URL(url);
242246
for (let googleHostRE of googleHostREs) {
243247
if (googleHostRE.test(parsedUrl.host)) {
248+
return true;
249+
}
250+
}
251+
return false;
252+
}
253+
254+
function isYouTubeURL (url) {
255+
const parsedUrl = new URL(url);
256+
for (let youtubeHostRE of youtubeHostREs) {
257+
if (youtubeHostRE.test(parsedUrl.host)) {
258+
return true;
259+
}
260+
}
261+
return false;
262+
}
244263

245-
// Ignore nothing when all ignore-settings are disabled
246-
if (! extensionSettings.ignore_searchpages && ! extensionSettings.ignore_youtube) {
247-
return true;
248-
}
249-
250-
// Ignore YouTube host when setting is enabled and host matches
251-
if (extensionSettings.ignore_youtube) {
252-
for (let youtubeHostRE of youtubeHostREs) {
253-
if (youtubeHostRE.test(parsedUrl.host)) {
254-
return false;
255-
}
256-
}
257-
}
258-
259-
// Ignore search page when setting is enabled and path matches
260-
if (extensionSettings.ignore_searchpages && ! SEARCHPAGE_PATHS.includes(parsedUrl.pathname)) {
261-
return true;
262-
}
264+
function isSearchPageURL (url) {
265+
const parsedUrl = new URL(url);
266+
for (let searchpagePathRE of searchpagePathREs) {
267+
if (searchpagePathRE.test(parsedUrl.pathname)) {
268+
return true;
263269
}
264270
}
265271
return false;
@@ -271,7 +277,17 @@ function shouldContainInto (url, tab) {
271277
return false;
272278
}
273279

274-
if (isGoogleURL(url)) {
280+
let handleUrl = isGoogleURL(url);
281+
282+
if (extensionSettings.ignore_youtube && isYouTubeURL(url)) {
283+
handleUrl = false;
284+
}
285+
286+
if (extensionSettings.ignore_searchpages && isSearchPageURL(url)) {
287+
handleUrl = false;
288+
}
289+
290+
if (handleUrl) {
275291
if (tab.cookieStoreId !== googleCookieStoreId) {
276292
// Google-URL outside of Google Container Tab
277293
// Should contain into Google Container

0 commit comments

Comments
 (0)