This repository was archived by the owner on Mar 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
106 lines (93 loc) · 2.46 KB
/
script.js
File metadata and controls
106 lines (93 loc) · 2.46 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const DataJSON = localStorage.getItem("Data");
const ValueJSON = localStorage.getItem("Value");
let Data=[];
let Value=[];
const inputText = document.getElementById('input_in');
const inputBtn = document.getElementById('button_in');
const inputImg = document.getElementById('button_img');
const inputVid = document.getElementById('button_vid');
const inputLink = document.getElementById('button_link');
const inputTrash = document.getElementById('button_trash');
const list = document.getElementById('list');
getData();
function getData(){
if(DataJSON && ValueJSON){
Data=JSON.parse(DataJSON);
Value=JSON.parse(ValueJSON);
}
for(let i=0; i < Data.length; i++){
inputText.value = Data[i];
switch(Value[i]){
case 1:
addText();
break;
case 2:
addImg();
break;
case 3:
addVid();
break;
case 4:
addLink();
break;
default:
addText();
break;
}
}
};
function addText(){
list.innerHTML += `<li>${inputText.value}</li>`;
Data.push(inputText.value);
Value.push(1);
setData();
inputText.value = '';
}
function addImg(){
list.innerHTML += `<li><img src='${inputText.value}'></li>`;
Data.push(inputText.value);
Value.push(2);
setData();
inputText.value = '';
}
function addVid(){
list.innerHTML += `<li>
<video controls>
<source src="${inputText.value}" type="video/youtu">
<source src="${inputText.value}" type="video/mp4">
<source src="${inputText.value}" type="video/ogg">
</video>
</li>`;
Data.push(inputText.value);
Value.push(3);
setData();
inputText.value = '';
}
function addLink(){
list.innerHTML += `<li><a target="_blank" href='${inputText.value}'>${inputText.value}</a></li>`;
Data.push(inputText.value);
Value.push(4);
inputText.value = '';
setData();
}
inputBtn.addEventListener("click", function() {
addText();
});
inputImg.addEventListener("click", function() {
addImg();
});
inputVid.addEventListener("click", function() {
addVid();
});
inputLink.addEventListener('click', function() {
addLink();
});
inputTrash.addEventListener('click', function() {
localStorage.removeItem("Data");
localStorage.removeItem("Value");
list.innerHTML='';
});
function setData(){
localStorage.setItem("Data",JSON.stringify(Data));
localStorage.setItem("Value",JSON.stringify(Value));
}