Skip to content

Commit

Permalink
Added two options (including options page):
Browse files Browse the repository at this point in the history
Ignore YouTube (to not being logged into Google on YouTube, originally done by https://github.com/yoasif/contain-google-minus-youtube, but without having that optionally)
Ignore search pages (to not being logged into Google for Google searches, includes maps and flight search)
  • Loading branch information
berrnd committed Mar 24, 2019
1 parent 7b40e4a commit 51dd4f1
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
34 changes: 33 additions & 1 deletion background.js
Expand Up @@ -33,6 +33,10 @@ const DEVELOPER_DOMAINS = [
"madewithcode.com", "design.google", "gallery.io", "domains.google", "material.io", "android.com", "chromium.org", "cobrasearch.com", "chromecast.com", "chrome.com", "chromebook.com", "madewithcode.com", "whatbrowser.org", "withgoogle.com", "web.dev",
];

const SEARCHPAGE_PATHS = [
"/search", "/maps", "/flights"
]


GOOGLE_DOMAINS = GOOGLE_DOMAINS.concat(GOOGLE_INTL_DOMAINS)
.concat(GOOGLE_SERVICES).concat(YOUTUBE_DOMAINS).concat(BLOGSPOT_DOMAINS).concat(ALPHABET_DOMAINS)
Expand All @@ -44,10 +48,12 @@ const MAC_ADDON_ID = "@testpilot-containers";

let macAddonEnabled = false;
let googleCookieStoreId = null;
let extensionSettings = {};

const canceledRequests = {};
const tabsWaitingToLoad = {};
const googleHostREs = [];
const youtubeHostREs = [];

async function isMACAddonEnabled () {
try {
Expand Down Expand Up @@ -147,6 +153,13 @@ function generateGoogleHostREs () {
for (let googleDomain of GOOGLE_DOMAINS) {
googleHostREs.push(new RegExp(`^(.*\\.)?${googleDomain}$`));
}
for (let youtubeDomain of YOUTUBE_DOMAINS) {
youtubeHostREs.push(new RegExp(`^(.*\\.)?${youtubeDomain}$`));
}
}

async function loadExtensionSettings () {
extensionSettings = await browser.storage.sync.get();
}

async function clearGoogleCookies () {
Expand Down Expand Up @@ -228,7 +241,25 @@ function isGoogleURL (url) {
const parsedUrl = new URL(url);
for (let googleHostRE of googleHostREs) {
if (googleHostRE.test(parsedUrl.host)) {
return true;

// Ignore nothing when all ignore-settings are disabled
if (! extensionSettings.ignore_searchpages && ! extensionSettings.ignore_youtube) {
return true;
}

// Ignore YouTube host when setting is enabled and host matches
if (extensionSettings.ignore_youtube) {
for (let youtubeHostRE of youtubeHostREs) {
if (youtubeHostRE.test(parsedUrl.host)) {
return false;
}
}
}

// Ignore search page when setting is enabled and path matches
if (extensionSettings.ignore_searchpages && ! SEARCHPAGE_PATHS.includes(parsedUrl.pathname)) {
return true;
}
}
}
return false;
Expand Down Expand Up @@ -376,6 +407,7 @@ async function containGoogle (options) {
console.log(error);
return;
}
loadExtensionSettings();
clearGoogleCookies();
generateGoogleHostREs();

Expand Down
8 changes: 7 additions & 1 deletion manifest.json
Expand Up @@ -26,10 +26,16 @@
"management",
"tabs",
"webRequestBlocking",
"webRequest"
"webRequest",
"storage"
],

"background": {
"scripts": ["background.js"]
},

"options_ui": {
"page": "options.html",
"browser_style": true
}
}
32 changes: 32 additions & 0 deletions options.html
@@ -0,0 +1,32 @@
<!DOCTYPE html>

<html>

<head>
<meta charset="utf-8">
</head>

<body>
<form>

<p>
<label>
<input type="checkbox" id="ignore_youtube" value="1">
Ignore YouTube
</label>
</p>

<p>
<label>
<input type="checkbox" id="ignore_searchpages" value="1">
Ignore search pages
</label>
</p>

<button type="submit">Save settings</button>

</form>
<script src="options.js"></script>
</body>

</html>
26 changes: 26 additions & 0 deletions options.js
@@ -0,0 +1,26 @@
function onOptionsPageSave(e)
{
e.preventDefault();

// Save settings
browser.storage.sync.set({
"ignore_youtube": document.querySelector("#ignore_youtube").checked,
"ignore_searchpages": document.querySelector("#ignore_searchpages").checked
});

browser.runtime.reload();
}

function onOptionsPageLoaded()
{
// Load saved settings or use defaults when nothing was saved yet
var storageItem = browser.storage.sync.get();
storageItem.then((res) =>
{
document.querySelector("#ignore_youtube").checked = res.ignore_youtube || false;
document.querySelector("#ignore_searchpages").checked = res.ignore_searchpages || false;
});
}

document.addEventListener("DOMContentLoaded", onOptionsPageLoaded);
document.querySelector("form").addEventListener("submit", onOptionsPageSave);

0 comments on commit 51dd4f1

Please sign in to comment.