-
Notifications
You must be signed in to change notification settings - Fork 7
/
background.js
172 lines (138 loc) · 4.93 KB
/
background.js
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
var session = new Session();
chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {
switch (request.type) {
case "addBug":
addAnnotation("Bug", request.name, request.imageURL);
break;
case "addIdea":
addAnnotation("Idea", request.name, request.imageURL);
break;
case "addNote":
addAnnotation("Note", request.name, request.imageURL);
break;
case "addQuestion":
addAnnotation("Question", request.name, request.imageURL);
break;
case "updateAnnotationName":
var AnnotationID = request.annotationID;
var newName = request.newName;
var annotations = session.getAnnotations();
var annotation = annotations[AnnotationID];
annotation.setName(newName);
break;
case "deleteAnnotation":
session.deleteAnnotation(request.annotationID);
break;
case "exportSessionCSV":
if (!exportSessionCSV())
sendResponse({
status: "nothing to export"
});
break;
case "exportSessionJSon":
if (!exportSessionJSon())
sendResponse({
status: "nothing to export"
});
break;
case "importSessionJSon":
var fileData = request.jSonSession;
if (!importSessionJSon(fileData))
sendResponse({
status: "nothing to import"
});
break;
case "clearSession":
clearSession();
break;
}
sendResponse({
status: "ok"
});
return true;
});
function addAnnotation(type, name, imageURL) {
var currentUrl;
var now = Date.now();
if (session.getAnnotations().length == 0) this.startSession();
chrome.tabs.query({
currentWindow: true,
active: true
},
function (tabs) {
currentUrl = tabs[0].url;
//alert(currentUrl);
switch (type) {
case "Bug":
var newBug = new Bug(name, currentUrl, now, imageURL);
session.addBug(newBug);
break;
case "Note":
var newNote = new Note(name, currentUrl, now, imageURL);
session.addNote(newNote);
break;
case "Idea":
var newIdea = new Idea(name, currentUrl, now, imageURL);
session.addIdea(newIdea);
break;
case "Question":
var newQuestion = new Question(name, currentUrl, now, imageURL);
session.addQuestion(newQuestion);
break;
}
});
}
function startSession() {
var systemInfo = getSystemInfo();
session = new Session(Date.now(), systemInfo);
};
function clearSession() {
session.clearAnnotations();
};
function exportSessionCSV() {
if (session.getAnnotations().length == 0) return false;
var exportService = new ExportSessionCSV(session);
var csvData = exportService.getCSVData();
var browserInfo = session.getBrowserInfo();
var browserInfoString = browserInfo.browser + "_" + browserInfo.browserVersion;
//Take the timestamp of the first Annotation
var startDateTime = session.getStartDateTime().toString('yyyyMMdd_HHmm');
var fileName = "ExploratorySession_" + browserInfoString + "_" + startDateTime + ".csv";
var pom = document.createElement('a');
var blob = new Blob([csvData], {
type: 'text/csv;charset=utf-8;'
});
var url = URL.createObjectURL(blob);
pom.href = url;
pom.setAttribute('download', fileName);
pom.click();
};
function exportSessionJSon() {
if (session.getAnnotations().length == 0) return false;
debugger;
var exportJSonService = new JSonSessionService();
var jsonData = exportJSonService.getJSon(session);
var browserInfo = session.getBrowserInfo();
var browserInfoString = browserInfo.browser + "_" + browserInfo.browserVersion;
//Take the timestamp of the first Annotation
var startDateTime = session.getStartDateTime().toString('yyyyMMdd_HHmm');
var fileName = "ExploratorySession_" + browserInfoString + "_" + startDateTime + ".json";
var pom = document.createElement('a');
var blob = new Blob([jsonData], {
type: 'application/json'
});
var url = URL.createObjectURL(blob);
pom.href = url;
pom.setAttribute('download', fileName);
pom.click();
};
function importSessionJSon(JSonSessionData) {
debugger;
var exportJSonService = new JSonSessionService();
var importedSession = exportJSonService.getSession(JSonSessionData);
if (importedSession == null)
return false;
clearSession();
session = importedSession;
return true;
};