forked from cgallello/UXCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
155 lines (120 loc) · 5.36 KB
/
background.js
File metadata and controls
155 lines (120 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
window.evaluation_in_progress = false;
// New tab is opened DURING evaluation
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
if (window.evaluation_in_progress == true){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "please open the tray"}, function(response) {});
});
}
}
})
// If browser action is clicked
chrome.browserAction.onClicked.addListener(function(){
if (window.evaluation_in_progress == false){
window.evaluation_in_progress = true;
//Google Analytics
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-57672068-1', 'auto');
ga('set', 'checkProtocolTask', function(){}); // Disable file protocol checking.
ga('require', 'displayfeatures');
ga('send', 'pageview', '/options.html');
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "please open the tray"}, function(response) {});
});
} else {
window.evaluation_in_progress = false;
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "please close the tray"}, function(response) {});
});
}
});
// Invoke tray
// From popup.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
/*// Start evaluation
if (request.greeting == "open the tray"){
console.log('i received a message from popup.js telling me to open the tray');
if (evaluation_in_progress == false){
window.evaluation_in_progress = true;
//Google Analytics
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-57672068-1', 'auto');
ga('set', 'checkProtocolTask', function(){}); // Disable file protocol checking.
ga('require', 'displayfeatures');
ga('send', 'pageview', '/options.html');
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "please open the tray"}, function(response) {
//console.log('i got a response that says'+response);
//sendResponse({farewell: "okay"});
});
});
}
}*/
// Close button clicked, evaluation stopped
if (request.greeting == "close_button_clicked"){
window.evaluation_in_progress = false;
}
// Stop evaluation
if (request.greeting == "stop_evaluation"){
window.evaluation_html = request.html;
chrome.tabs.create({url: 'evaluationpage.html'});
window.evaluation_in_progress = false;
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "stopping_evalution"}, function(response) {
});
});
}
// Take screenshot
if (request.greeting == "take_screenshot"){
chrome.tabs.captureVisibleTab(null,{},function(dataUrl){
window.screenshot = dataUrl;
sendResponse({farewell: window.screenshot});
});
return true;
}
// Save data
if (request.greeting == "setData"){
var saved_data = request.data_object;
localStorage.setItem('saved_data', JSON.stringify(saved_data));
}
// Get data
if (request.greeting == "getData"){
var saved_data_string = localStorage.getItem('saved_data');
var saved_data = $.parseJSON(saved_data_string);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "heres_ur_data", dataObject: saved_data}, function(response) {
//sendResponse({farewell: "okay"});
});
});
}
// Pass evaluation info to evaluation page
if (request.greeting == "gimme_evaluation_info"){
sendResponse({greeting: "heres_ur_data", evalInfo: window.evaluation_html});
//chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
//chrome.tabs.sendMessage(tabs[0].id, {greeting: "heres_ur_data", evalInfo: window.evaluation_html}, function(response) {
//sendResponse({farewell: "okay"});
//});
//});
}
}
);
/*
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-57672068-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();*/