Skip to content

Commit

Permalink
Add port for Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
MorbZ committed Feb 17, 2016
1 parent 7e724ae commit c8c51df
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
5 changes: 5 additions & 0 deletions chrome/_locales/de/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"appDesc": {
"message": "Suche anonym auf Google während du weiterhin bei Youtube, Gmail, usw. eingeloggt bleibst."
}
}
5 changes: 5 additions & 0 deletions chrome/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"appDesc": {
"message": "Search anonymously on Google while staying logged in on services such as Youtube, Gmail, etc."
}
}
97 changes: 97 additions & 0 deletions chrome/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"use strict";

// We can't use a content-script since URL-regexes don't allow checking for wildcard TLDs
let contentPattern = /^https?:\/\/((www|encrypted)\.)?google\..*/;
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(contentPattern.test(tab.url)) {
// Remove cookie/privacy hints that would popup on every page visit otherwise
chrome.tabs.insertCSS(tabId, {
file: 'google.css'
});
}
});

// Register header event listener
chrome.webRequest.onBeforeSendHeaders.addListener(
onBeforeHeaders,
{
urls: ['<all_urls>']
},
[
'requestHeaders',
'blocking'
]
);

// Remove cookie from headers
function onBeforeHeaders(details) {
// Check if Google search URL
if(!isSearchUrl(details.url)) {
return;
}

// Get Cookie
var headers = details.requestHeaders;
for(var i = 0; i < headers.length; i++) {
if(headers[i].name == 'Cookie') {
// Remove cookies
headers.splice(i, 1);

// Return new headers
return {
requestHeaders: headers
};
}
}
}

/* URLs */
// If URL considered a Google search URL
function isSearchUrl(url) {
// Check blacklist
if(!isBlacklisted(url)) {
return false;
}

// Check whitelist
if(isWhitelisted(url)) {
return false;
}
return true;
}

// Is blacklisted URL?
let urlBlacklist = [
//Google search page
/^https?:\/\/((search|www|encrypted)\.)?google\.[^\/]+\/?[^\/]*$/i,

//Google autocomplete
/^https?:\/\/((search|www|encrypted)\.)?google\.[^\/]+\/complete\/.*$/i,
];
function isBlacklisted(url) {
return testRegexAry(urlBlacklist, url);
}

// Is whitelisted URL?
let urlWhitelist = [
// Google Voice
/^https?:\/\/www\.google\.[a-z]*?\/voice/i,

// Google Maps
/^https?:\/\/www\.google\.[a-z]*?\/maps/i,
/^https?:\/\/www\.google\.[a-z]*?\/s\?tbm=map/i,
];
function isWhitelisted(url) {
return testRegexAry(urlWhitelist, url);
}

// Test regex array on given string
function testRegexAry(ary, string) {
for(var key in ary) {
var pattern = ary[key];
if(pattern.test(string)) {
return true;
}
}
return false;
}
7 changes: 7 additions & 0 deletions chrome/google.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#epbar,
#pmocntr2,
#cnsh, /* Privacy hint on Google homepage */
#cnso /* Privacy hint ontop of search results */
{
display: none !important;
}
Binary file added chrome/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"manifest_version": 2,
"name": "Searchonymous",
"version": "1.0.5",
"description": "__MSG_appDesc__",
"default_locale": "en",
"icons": {
"128": "icon128.png"
},
"permissions": [
"tabs",
"webRequest",
"webRequestBlocking",
"<all_urls>"
],
"background": {
"scripts": [ "background.js" ]
}
}

0 comments on commit c8c51df

Please sign in to comment.