-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathfileUpload.js
More file actions
57 lines (46 loc) · 1.73 KB
/
Copy pathfileUpload.js
File metadata and controls
57 lines (46 loc) · 1.73 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
document.getElementById('fileUpload')
.addEventListener('change', getFile)
function getFile(event) {
const input = event.target
if ('files' in input && input.files.length > 0) {
const div_JSONinput = document.getElementById("div_JSONinput")
const JSONinput = document.getElementById("JSONinput")
const JSONinput_header_get = document.getElementById("JSONinput_header")
if (JSONinput) {
JSONinput.remove()
}
if (JSONinput_header_get) {
JSONinput_header_get.remove()
}
const JSONinput_header = document.createElement("h4")
JSONinput_header.id = "JSONinput_header"
JSONinput_header.innerHTML = "ATT&CK Navigator Layer (TTPs)"
JSONinput_header.style.textAlign = "center"
div_JSONinput.appendChild(JSONinput_header)
const textarea = document.createElement("textarea")
textarea.className = "form-control"
textarea.id = "JSONinput"
textarea.rows = "10"
div_JSONinput.appendChild(textarea)
const JSONinput_final = document.getElementById("JSONinput")
const output_threat = document.getElementById("output_threat")
output_threat.innerHTML = 'My Threat Intelligence'
placeFileContent(
JSONinput_final,
input.files[0])
window.location.href = 'https://controlcompass.github.io/risk#controls'
}
}
function placeFileContent(target, file) {
readFileContent(file).then(content => {
target.textContent = content
}).catch(error => console.log(error))
}
function readFileContent(file) {
const reader = new FileReader()
return new Promise((resolve, reject) => {
reader.onload = event => resolve(event.target.result)
reader.onerror = error => reject(error)
reader.readAsText(file)
})
}