forked from MilanDonhowe/studentSelect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
45 lines (29 loc) · 951 Bytes
/
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
'use strict';
chrome.runtime.onInstalled.addListener(function() {
console.log(' background.js loaded');
});
// Listen for data request from detect.js
chrome.extension.onConnect.addListener(function(port) {
console.log("Connected... ")
port.onMessage.addListener(function(msg) {
console.log("message received " + msg);
let txt = ''
let xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.status == 200 && xmlhttp.readyState == 4){
// Get text from file
txt = xmlhttp.responseText;
// Get each line of file into an array
let stripped = txt.split('\n')
// Remove empty lines and undefined lines
let studentNames = stripped.filter(slimDown);
function slimDown(value){
return value != "" && value != undefined
}
port.postMessage(studentNames);
}
};
xmlhttp.open("GET", msg + ".txt", true);
xmlhttp.send();
});
});