forked from Mark-Yoo/Gamsung_writing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
79 lines (66 loc) · 2.56 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
(function () {
const btn = document.querySelector('.save');
const del = document.querySelector('.delete');
const getBoard = document.querySelector('.board');
const tempList = [];
const topic = ['옛 사진', '먼지', '개성', '과정', '안부', '새벽',
'걷기', '발자국', '성격', '메모', '보관', '목소리', '그늘', '시선', '안경', '현실', '그림자', '규칙', '핑계'];
let _randomTopic = 0;
const storage_key = 'writeSave';
function saveWrite() {
// tempList.forEach(function (item) {
// });
localStorage.setItem(storage_key, JSON.stringify(tempList));
}
function loadWrite() {
let load = localStorage.getItem(storage_key);
load = JSON.parse(load);
if (load === null) {
return null;
}
console.log(load);
load.forEach(function (item) {
console.log(item);
// getBoard.innerHTML = item.textContent;
tempList[tempList.length] = item;
});
}
loadWrite();
function saveWrite() {
// tempList.forEach(function (item) {
// });
localStorage.setItem(storage_key, JSON.stringify(tempList));
}
// 글감 랜덤으로 던져서 뿌려주기
function writeTopic() {
const randomTopic = Math.floor(Math.random() * topic.length);
document.querySelector('.title').innerHTML = `<h2>${topic[randomTopic]}</h2>`;
_randomTopic = randomTopic;
}
writeTopic();
// 사용자가 입력한 글 가져오기
btn.addEventListener('click', function (e) {
const getValue = getBoard.textContent;
const tempObj = {};
tempObj.title = topic[_randomTopic];
tempObj.textContent = getValue;
tempList[tempList.length] = tempObj;
console.log(tempList);
saveWrite();
});
// focus되면 기본 글인 '여기에 글을...' 이 사라짐.
getBoard.addEventListener('focus', function (e) {
e.target.textContent = '';
});
del.addEventListener('click', function (e) {
// saveWrite();
// localStorage.clear();
// setTimeout(function () {
// location.reload();
// }, 1000);
});
// focus되면 기본 글인 '여기에 글을...' 이 사라짐.
// getBoard.addEventListener('focus', function (e) {
// e.target.textContent = '';
// });
}());