forked from MilanDonhowe/studentSelect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.js
More file actions
67 lines (44 loc) · 1.5 KB
/
edit.js
File metadata and controls
67 lines (44 loc) · 1.5 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
'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("btn").addEventListener("click", selectedPeriod);
}
let save =() => {
if (periodChange == 0) {
periodChange = document.getElementById("periodSelect").value;
}
let textdata = document.getElementById('display').value;
let stripped = textdata.split('\n');
let studentNames = stripped.filter(slimDown);
function slimDown(value){
return value != "" && value != undefined
}
//console.log(studentNames.unshift(periodChange));
studentNames.unshift(periodChange);
let port = chrome.extension.connect({
name: "Save Student Names"
});
port.postMessage(studentNames);
}
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;
//console.log(msg);
document.getElementById('display').value += students.join('\n');;
//add text to text-area
//for(let i=0;i<students.length;i++){
// document.getElementById('display').value += students[i];
//}
});
}