Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only match FB strings on hostnames rather than the entire URI. #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions firefox/chrome/content/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,15 @@
Authors (one per line):

Brian Kennish <[email protected]>
Jonty Wareing <[email protected]>
*/

/* The XPCOM interfaces. */
const FACEBOOK_INTERFACES = Components.interfaces;

/* The domain names Facebook phones home with, lowercased. */
const FACEBOOK_DOMAINS = ['facebook.com', 'facebook.net', 'fbcdn.net'];

/*
Determines whether any of a bucket of domains is part of a URL, regex free.
*/
function isMatching(url, domains) {
const DOMAIN_COUNT = domains.length;
for (var i = 0; i < DOMAIN_COUNT; i++)
if (url.toLowerCase().indexOf(domains[i], 2) >= 2) return true;
// A valid URL has at least two characters ("//"), then the domain.
}
const FACEBOOK_REGEX = RegExp('^https?://[^?/]*(' + FACEBOOK_DOMAINS.join('|') + ')[/?^]*', 'i');

/* Traps and selectively cancels a request. */
Components.classes['@mozilla.org/observer-service;1']
Expand All @@ -52,7 +44,7 @@ Components.classes['@mozilla.org/observer-service;1']
);
subject.referrer.ref;
// HACK: The URL read otherwise outraces the window unload.
BROWSER && !isMatching(BROWSER.currentURI.spec, FACEBOOK_DOMAINS) &&
isMatching(subject.URI.spec, FACEBOOK_DOMAINS) &&
BROWSER && !BROWSER.currentURI.spec.match(FACEBOOK_REGEX) &&
subject.URI.spec.match(FACEBOOK_REGEX) &&
subject.cancel(Components.results.NS_ERROR_ABORT);
}}, 'http-on-modify-request', false);
21 changes: 7 additions & 14 deletions webkit/fbdc.safariextension/chrome/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,16 @@
Authors (one per line):

Brian Kennish <[email protected]>
Jonty Wareing <[email protected]>
*/

/* The domain names Facebook phones home with, lowercased. */
const DOMAINS = ['facebook.com', 'facebook.net', 'fbcdn.net'];

/*
Determines whether any of a bucket of domains is part of a URL, regex free.
*/
function isMatching(url, domains) {
const DOMAIN_COUNT = domains.length;
for (var i = 0; i < DOMAIN_COUNT; i++)
if (url.toLowerCase().indexOf(domains[i], 2) >= 2) return true;
// A valid URL has at least two characters ("//"), then the domain.
}
/* The domain names Facebook phones home with */
const FACEBOOK_DOMAINS = ['facebook\.com', 'facebook\.net', 'fbcdn\.net'];
const FACEBOOK_REGEX = RegExp('^https?://[^?/]*(' + FACEBOOK_DOMAINS.join('|') + ')[/?^]*', 'i');

/* Traps and selectively cancels a request. */
if (!isMatching(location.href, DOMAINS))
if (!location.href.match(FACEBOOK_REGEX)) {
document.addEventListener('beforeload', function(event) {
if (isMatching(event.url, DOMAINS)) event.preventDefault();
if (event.url.match(FACEBOOK_REGEX)) event.preventDefault();
}, true);
}