Commit 0e768177 authored by Craig Earley's avatar Craig Earley
Browse files

duration from the extension start time to reaching a valid stop url sent from background to content

parent 9af92ffe
var debug = 1;
var start_time = Date.now();
var stop_time;
var duration;
var urls_to_compare = readTextFile("../data/urls.txt");
/* this code base courtesty of https://stackoverflow.com/questions/14446447/javascript-read-local-text-file#14446538*/
......@@ -15,6 +17,13 @@ function readTextFile(file){
rawFile.send(null);
return(lines);}
// abstracted in case we want to modify how we parse the duration
function get_duration(){
stop_time = Date.now();
var local_duration = stop_time - start_time;
return local_duration;
}
function is_a_stop(possible_stop_urls, current_url){
if (debug){
console.log("URLs to compare");
......@@ -37,6 +46,7 @@ chrome.tabs.onUpdated.addListener(function (tabID, changeInfo, tab) {
if (debug){ console.log(url);}
if (changeInfo.status=='complete'){
if (is_a_stop(urls_to_compare, url)){
chrome.tabs.sendMessage(tab.id, { action: 'match' });
duration = get_duration();
chrome.tabs.sendMessage(tab.id, { action: duration });
if (debug) {console.log("background found match");}} }
});});
chrome.runtime.onMessage.addListener(function (msg) {
/* We received a message, let's do as instructed */
if (msg.action == 'match') {
window.alert('Google!');
}
// if (msg.action == 'match') {
console.log(msg.action);
// }
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment