forked from ecraft2learn/ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-logs.html
More file actions
69 lines (66 loc) · 2.44 KB
/
fetch-logs.html
File metadata and controls
69 lines (66 loc) · 2.44 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
68
69
<!DOCTYPE html>
<html>
<head>
<link href="css/ai-teacher-guide.css" rel="stylesheet">
<title>Fetching and resetting Snap! logs</title>
<script type="text/javascript">
const fetch_logs = () => {
let last_log_counter = localStorage.getItem('log counter');
if (!last_log_counter) {
return "[]";
}
let logs = "";
for (let i = 1; i < last_log_counter; i++) {
logs += localStorage.getItem(i) + ",";
}
return "[" + logs.slice(0, logs.length-1) + "]"; // remove last comma
};
const download_string = (label, name, data) => {
const button = create_anchor_that_looks_like_a_button(label);
const file = new Blob([data], {type: 'text/plain;charset=UTF-8'});
button.href = URL.createObjectURL(file);
button.download = name;
return button;
};
const create_anchor_that_looks_like_a_button = (label, listener) => {
let button = document.createElement('a');
button.innerHTML = label;
button.className = 'generic-button';
button.style.marginRight = "12px";
button.href = "#";
button.addEventListener('click', listener);
return button;
};
// const copy_logs_to_clipboard = () => {
// if (navigator.clipboard) {
// navigator.clipboard.writeText(fetch_logs());
// } else {
// const div = document.createElement('div');
// div.innerText = fetch_logs();
// document.body.appendChild(div);
// }
// };
const reset_logs = () => {
if (confirm("Are you sure you want to delete the Snap! logs stored in this browser?")) {
localStorage.clear();
}
};
window.addEventListener('DOMContentLoaded', () => {
// const fetch_logs_button = document.createElement('button');
// fetch_logs_button.innerHTML = "Click to copy current logs to the clipboard";
// fetch_logs_button.addEventListener('click', copy_logs_to_clipboard);
// fetch_logs_button.classList.add('generic-button');
const download_logs_button =
download_string("Download logs",
"logs-" + new Date().getTime() + ".js",
fetch_logs());
document.body.appendChild(download_logs_button);
const clear_logs_button = document.createElement('button');
clear_logs_button.innerHTML = "Click to permanently remove the logs from this browser";
clear_logs_button.addEventListener('click', reset_logs);
clear_logs_button.classList.add('generic-button');
document.body.appendChild(clear_logs_button);
});
</script>
</head>
</html>