Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Seniors
craig1617
Commits
0e768177
Commit
0e768177
authored
Nov 29, 2016
by
Craig Earley
Browse files
duration from the extension start time to reaching a valid stop url sent from background to content
parent
9af92ffe
Changes
2
Hide whitespace changes
Inline
Side-by-side
extension/js/background.js
View file @
0e768177
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
"
);}}
}
});});
extension/js/content.js
View file @
0e768177
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
);
//
}
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment