Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
craig1617
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Seniors
craig1617
Commits
0e768177
Commit
0e768177
authored
8 years ago
by
Craig Earley
Browse files
Options
Downloads
Patches
Plain Diff
duration from the extension start time to reaching a valid stop url sent from background to content
parent
9af92ffe
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
extension/js/background.js
+12
-2
12 additions, 2 deletions
extension/js/background.js
extension/js/content.js
+3
-3
3 additions, 3 deletions
extension/js/content.js
with
15 additions
and
5 deletions
extension/js/background.js
+
12
−
2
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
"
);}}
}
});});
This diff is collapsed.
Click to expand it.
extension/js/content.js
+
3
−
3
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
);
//
}
});
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment