Skip to content

Commit

Permalink
Firefox: Update CSS, remove JS, don't modify cookies, use JPM
Browse files Browse the repository at this point in the history
  • Loading branch information
MorbZ committed Feb 17, 2016
1 parent 1bbb4d4 commit b1a384f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 178 deletions.
8 changes: 6 additions & 2 deletions firefox/data/google.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#epbar, #pmocntr2 {
#epbar,
#pmocntr2,
#cnsh, /* Privacy hint on Google homepage */
#cnso /* Privacy hint ontop of search results */
{
display: none !important;
}
}
22 changes: 0 additions & 22 deletions firefox/data/google.js

This file was deleted.

Empty file removed firefox/doc/main.md
Empty file.
77 changes: 0 additions & 77 deletions firefox/lib/cookie.js

This file was deleted.

43 changes: 15 additions & 28 deletions firefox/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,37 @@
//import custom modules
let observer = require("observer");
let cook = require("cookie");
let urls = require("urls");
// Import custom modules
let observer = require("./observer");
let urls = require("./urls");

//create observer
// Create observer
observer.createObserver(observe);

//observe http modify request
// Observe HTTP modify request
function observe(httpChannel) {
var url = httpChannel.URI;

//check blacklist
if(!urls.isBlacklisted(url)) {
return;
}
var url = httpChannel.URI.spec;

//check whitelist
if(urls.isWhitelisted(url)) {
// Check if Google search URL
if(!urls.isSearchUrl(url)) {
return;
}

//set cleaned cookie
try {
var cookie = httpChannel.getRequestHeader("Cookie");
} catch(e) {}
if(cookie != undefined) {
cookie = cook.cleanCookie(cookie);
httpChannel.setRequestHeader("Cookie", cookie, false);
}
// Remove cookie from headers
httpChannel.setRequestHeader("Cookie", "", false);
}

//load
// Addon load
exports.main = function() {
observer.register();
};

//unload
// Addon unload
exports.onUnload = function() {
observer.unregister();
}

//get rid of page decoration and change country name to anonymous
// Remove cookie/privacy hints that would popup on every page visit otherwise
let data = require("sdk/self").data;
require("sdk/page-mod").PageMod({
include: /^https?:\/\/((www|encrypted)\.)?google\..*/,
contentScriptWhen: "ready",
contentStyleFile: data.url("google.css"),
contentScriptFile: data.url("google.js")
});
contentStyleFile: data.url("google.css")
});
28 changes: 14 additions & 14 deletions firefox/lib/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const {Cc, Ci} = require("chrome");
const observer_topic = "http-on-modify-request";
let observer = null;

//create observer
// Create observer
function createObserver(callback) {
observer = {
observe: function(subject, topic, data)
observe: function(subject, topic, data)
{
if(topic == observer_topic) {
if(topic == observer_topic) {
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
if(httpChannel != null && httpChannel.getRequestHeader != undefined) {
callback(httpChannel);
Expand All @@ -19,21 +19,21 @@ function createObserver(callback) {
}
exports.createObserver = createObserver;

//register observer
function register()
{
// Register observer
function register()
{
getObserverService().addObserver(observer, observer_topic, false);
}
exports.register = register;

//unregister observer
function unregister()
{
getObserverService().removeObserver(observer, observer_topic);
// Unregister observer
function unregister()
{
getObserverService().removeObserver(observer, observer_topic);
}
exports.unregister = unregister;

//get observer service
function getObserverService() {
return Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
}
// Get observer service
function getObserverService() {
return Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
}
47 changes: 27 additions & 20 deletions firefox/lib/urls.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
//is blacklisted url?
let blacklist = [
// 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;
}
exports.isSearchUrl = isSearchUrl;

// 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(blacklist, url.spec);
return testRegexAry(urlBlacklist, url);
}
exports.isBlacklisted = isBlacklisted;

//is whitelisted url?
let whitelist = [
//send the correct cookies when settings are changed, otherwise Google
// won't set our new cookies.
//TODO: find out how Google detects this and make this request anonymous
// as well, not critical though, as it is no search.
/^https?:\/\/((www|encrypted)\.)?google\.[a-z]*?\/setprefs\?/i,

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

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

//test regex array on given string
// Test regex array on given string
function testRegexAry(ary, string) {
for(var key in ary) {
var pattern = ary[key];
Expand All @@ -40,4 +47,4 @@ function testRegexAry(ary, string) {
}
}
return false;
}
}
7 changes: 4 additions & 3 deletions firefox/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "searchonymous",
"title": "Searchonymous",
"id": "jid1-WF1v8esuNM9pRg",
"description": "Search anonymously on Google, while keeping your search preferences and stay logged in on services such as Youtube, Gmail, etc.",
"id": "jid1-WF1v8esuNM9pRg@jetpack",
"description": "Search anonymously on Google while staying logged in on services such as Youtube, Gmail, etc.",
"author": "MorbZ",
"license": "MPL 2.0",
"version": "1.0.3"
"version": "1.0.5",
"main": "lib/main.js"
}
12 changes: 0 additions & 12 deletions firefox/test/test-main.js

This file was deleted.

0 comments on commit b1a384f

Please sign in to comment.