forked from MilanDonhowe/studentSelect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit.js
69 lines (47 loc) · 1.56 KB
/
edit.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
'use strict';
// This variable is for setting which file to write to (post request).
var periodChange = 0;
window.onload = function() {
document.getElementById("save").addEventListener("click", save);
document.getElementById("periodSelect").addEventListener("click", selectedPeriod);
}
let save =() => {
if (periodChange == 0) {
periodChange = document.getElementById("periodSelect").value;
}
let textdata = document.getElementById('display').value;
console.log(textdata);
// to-do make post request to .txt files.
// Still trying to figure this one out...
/*
let postRequest = new XMLHttpRequest();
postRequest.onreadystatechange = function(){
if (postRequest.readyState == 4 && postRequest.status == 200){
console.log('success!')
} else {
console.log('error has happened')
}
};
postRequest.open("PUT", periodChange + ".txt", true);
postRequest.setRequestHeader("X-Custom-Header", "value");
postRequest.send(textdata);
*/
}
let selectedPeriod = () => {
let period = document.getElementById("periodSelect").value;
// Store in variable so we can post to file later
periodChange = period;
let port = chrome.extension.connect({
name: "Load Student Names"
});
port.postMessage(period);
port.onMessage.addListener(function(msg) {
console.log("message received");
console.log(msg);
let students = msg;
//add text to text-area
for(let i=0;i<students.length;i++){
document.getElementById('display').value += students[i];
}
});
}