-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (55 loc) · 2.33 KB
/
script.js
File metadata and controls
66 lines (55 loc) · 2.33 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
const container = document.getElementById('container');
const master_container = document.getElementById('master_container');
const todo = document.getElementsByClassName('todo');
const output = document.getElementById('output');
const save_html = document.getElementById("save_html");
var form = document.forms.load_html;
var container_counter = 0;
form.myfile.addEventListener("change", function (e) {
var result = e.target.files[0];
//FileReaderのインスタンスを作成する
var reader = new FileReader();
//読み込んだファイルの中身を取得する
reader.readAsText(result);
//ファイルの中身を取得後に処理を行う
reader.addEventListener('load', function () {
//ファイルの中身を改行で区切る
const result_split = reader.result.split("\n");
//コンテナを初期化する
for(i=0;i<(container_counter);i++){
let remove_container = master_container.removeChild(master_container.firstElementChild);
}
container_counter = 0;
//ファイルの中身をtodo内に転送する
for (i = 0; i < result_split.length; i++) {
//これは2の配列をtodoに格納する処理
if (i != 0) {
add_input()
}
todo[i].value = result_split[i];
}
})
})
function add_input() {
container_counter++;
let new_container = document.createElement('div');
new_container.id = "container"
master_container.appendChild(new_container);
new_container.innerHTML = '<input type="text" class="todo" value=""><input type="button" value="追加" id="add" onclick="add_input()">';
}
function decide() {
const random = Math.floor((Math.random() * 100) % todo.length);
output.innerHTML = "<h2>あなたが今日やるのは...." + todo[random].value + "です</h2>";
}
save_html.addEventListener('click', function () {
var save_data = "";
for (i = 0; i < todo.length; i++) {
if (i != (todo.length-1)) {
save_data = save_data + todo[i].value + "\n";
}else{
save_data = save_data + todo[i].value;
}
}
const save_create = new Blob([save_data], { "type": "text/plain" });
save_html.href = window.URL.createObjectURL(save_create);
})