Skip to content

Commit

Permalink
implemented whitelist/blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
priestc committed Feb 14, 2015
1 parent 532132f commit bee6b8e
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions microtip.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ function get_tips() {
return tips_on_this_page
}

// testcases:
// pass_blacklist_and_whitelist('whitelist', ['aa', 'bb'], 'aa') == true; // in whitelist
// pass_blacklist_and_whitelist('whitelist', ['aa', 'bb'], 'xx') == false; // not in whitelist
// pass_blacklist_and_whitelist('blacklist', ['aa', 'bb'], 'aa') == false; // in blacklist
// pass_blacklist_and_whitelist('blacklist', ['aa', 'bb'], 'cc') == true; // not in blacklist
function pass_blacklist_and_whitelist(setting, domains, this_domain) {
// setting: either 'blacklist' or 'whitelist'
// domains: list of strings (domain's that make up the white/blacklist)
// this_domain: the domain that this page is on
// returns: true or false, depending on whether this_domain passes or fails the black/whitelist

for(var i = 0; i < domains.length; i++){
var domain = domains[i];
if(domain == this_domain) {
return setting == 'whitelist';
}
};

return setting == 'blacklist';
}


chrome.storage.sync.get({
when_to_send: null,
blacklist_or_whitelist: null,
Expand All @@ -25,24 +47,37 @@ chrome.storage.sync.get({
return // No tips found
}

var pblwl = true;
if(items.blacklist_or_whitelist != 'none') {
// determine if this page's domain jives with the users black/whitelists.
var pblwl = pass_blacklist_and_whitelist(
items.blacklist_or_whitelist, items.domain_list, window.location.host
)
}

if(!pblwl) {
console.log("Autotip canceled because of", items.blacklist_or_whitelist);
console.log(items.domain_list, window.location.host);
}

console.log("Autotip extension found " + tips.length + " microtip meta tags on this page");
chrome.runtime.sendMessage({found_tips: tips});

if(items.when_to_send == '5mins') {
var five_minute_counter_start = new Date()
if(pblwl && items.when_to_send == '5mins') {
var five_minute_counter_start = new Date();
intervalID = setInterval(function() {
// update popup status every 1 second. After 5 minutes, make the tip
// update popup status every 1 second. After 5 minutes (or whatever the setting is), make the tip
var seconds_to_go = Math.floor(items.interval_seconds - ((new Date() - five_minute_counter_start) / 1000));
if(seconds_to_go <= 0) {
chrome.runtime.sendMessage({tips: tips, perform_tip: 'auto'});
console.log('5 minutes past, tip made');
clearInterval(intervalID);
} else {
var msg = "Sending tip in " + seconds_to_go + " Seconds"
var msg = "Sending tip in " + seconds_to_go + " Seconds";
chrome.runtime.sendMessage({popup_timer: msg});
}
}, 1000);
} else if(items.when_to_send == 'immediately') {
} else if(pblwl && items.when_to_send == 'immediately') {
// go ahead and make the tip automatically.
chrome.runtime.sendMessage({tips: tips, perform_tip: 'auto'});
}
Expand Down

0 comments on commit bee6b8e

Please sign in to comment.