-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
94 lines (74 loc) · 2.47 KB
/
popup.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
let makeChart = (AA, A, BBB, BB, B, CCC, CC, C, DDD, DD) =>
{
let ctx = document.getElementById('chart').getContext('2d');
let myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['A+/A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D'],
datasets: [{
label: '# of Votes',
data: [AA, A, BBB, BB, B, CCC, CC, C, DDD, DD],
backgroundColor: [
'#66ff00',
'#a6ff00',
'#d1ff00',
'#e6ff00',
'#ffee00',
'#ffd800',
'#ffae00',
'#ff9800',
'#ff5800',
'#ff1800'
],
borderColor: [
'#66ff00',
'#a6ff00',
'#d1ff00',
'#e6ff00',
'#ffee00',
'#ffd800',
'#ffae00',
'#ff9800',
'#ff5800',
'#ff1800'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
stepSize: 1
}
}]
}
}
});
}
const formatInfo = (info) => { //Function to parse the array and gather number of grades
let labels = ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D'];
let results = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for(let i=0; i<info.length; i++){
for(let j=0; j<labels.length; j++){
if(info[i] === labels[j]){
results[j]++;
break;
}
}
}
makeChart(results[0]+results[1], results[2], results[3], results[4], results[5],
results[6], results[7], results[8], results[9], results[10], results[11]); //Calling make char function with grade #s as parameters
}
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if(message.text === 'data'){
formatInfo(message.info);
}
});
const prompted = () => { //Sends a message to the content script to tell it to run
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, 'execute');
});
}
prompted(); //Runs when the popup is opened