forked from andywang23/cs-chrome-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
239 lines (205 loc) · 6.41 KB
/
index.html
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html>
<head>
<style>
html {
background: #bdc3c7; /* fallback for old browsers */
background: -webkit-linear-gradient(
to right,
#2c3e50,
#bdc3c7
); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(
to right,
#2c3e50,
#bdc3c7
); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
font-family: 'Roboto', sans-serif;
}
h1 {
color: white;
}
.notes-form,
.notes-list {
display: flex;
justify-content: center;
list-style: none;
width: 100%;
}
.notes-list {
flex-direction: column;
align-items: center;
min-height: 200px;
}
li {
margin: 5px;
}
.notes-text-input {
height: 50px;
width: 100%;
max-width: 1216px;
font-size: 130%;
overflow: auto;
text-align: top;
background-color: gray;
resize: none;
}
.notes-submit-btn {
background-color: lightslategray;
border: none;
width: 61px;
font-weight: bold;
}
.notes-submit-btn:hover {
cursor: pointer;
}
::placeholder {
color: lightgrey;
opacity: 1;
}
.notes-text-input:focus {
background-color: white;
color: black;
}
.timeStamp {
font-size: 80%;
cursor: pointer;
font-style: italic;
margin-right: 5px;
color: white;
}
li {
font-size: 120%;
display: flex;
justify-content: center;
align-items: center;
}
li * {
margin: 1px 5px;
}
.delete-btn {
width: 25px;
height: 25px;
border-radius: 2rem;
box-shadow: none;
}
</style>
</head>
<body>
<center><h1>Welcome to Zen Note</h1></center>
<center><div id="player"></div></center>
<form class="notes-form">
<textarea
class="notes-text-input"
type="text"
rows="5"
placeholder="Type Your Notes Here.."
></textarea>
<input class="notes-submit-btn" type="submit" />
</form>
<div class="notes-container">
<ul class="notes-list"></ul>
</div>
<script>
const vidURL = document.URL.substring(65);
let localStore = window.localStorage;
// localStore.clear();
// console.log(localStore.getItem(vidURL));
// console.log(localStore);
//iterate over localStore and put old notes onto DOM
//each key in localStore is a unique ID string combining
//the html code for the span and the timestamp in seconds
//when the note was created
for (const span in localStore) {
if (
span !== 'length' &&
span !== 'key' &&
span !== 'getItem' &&
span !== 'setItem' &&
span !== 'removeItem' &&
span !== 'clear' &&
span.substring(0, 11) === vidURL
) {
let oldItem = document.createElement('li');
oldItem.innerHTML = `<button class="delete-btn">X</button>${span.substring(
11
)} ${localStore[span]}`;
document.querySelector('ul').append(oldItem);
let deleteBtns = document.querySelectorAll('.delete-btn');
Array.from(deleteBtns).forEach((el) => {
el.addEventListener('click', deleteNote);
});
let timeStamps = document.querySelectorAll('.timeStamp');
Array.from(timeStamps).forEach((el) => {
el.addEventListener('click', timeTrack);
});
}
}
function deleteNote(evt) {
//delete the li that the button is attached to
//then delete from local storage
evt.target.parentNode.remove();
const deletedKey = evt.target.parentNode.innerHTML.substring(37, 87);
console.log(deletedKey);
localStore.removeItem(`${vidURL}${deletedKey}`);
console.log(localStore);
}
//youtube API setup
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '720',
width: '1280',
videoId: vidURL,
events: {
onReady: function onPlayerReady(event) {
event.target.playVideo();
},
},
});
}
//returns a span with a unique ID based on the timestamp of the video when user comments
function getTime() {
const seconds = player.getCurrentTime();
let minutes = `${Math.floor(seconds / 60)}`;
let leftoverSeconds = `${Math.floor(seconds % 60)}`;
if (minutes.length < 2) minutes = `0${minutes}`;
if (leftoverSeconds.length < 2) leftoverSeconds = `0${leftoverSeconds}`;
return `<span class="timeStamp" id="${seconds}">${minutes}:${leftoverSeconds}</span>`;
}
function timeTrack(evt) {
player.seekTo(evt.target.id);
}
function submitNote(evt) {
evt.preventDefault();
const newNote = document.querySelector('.notes-text-input').value;
document.querySelector('.notes-text-input').value = '';
const timeStamp = getTime();
document.querySelector(
'.notes-list'
).innerHTML += `<li><button class="delete-btn">X</button>${timeStamp} ${newNote} </li>`;
localStorageSet(timeStamp, newNote);
let deleteBtns = document.querySelectorAll('.delete-btn');
Array.from(deleteBtns).forEach((el) => {
el.addEventListener('click', deleteNote);
});
let timeStamps = document.querySelectorAll('.timeStamp');
Array.from(timeStamps).forEach((el) => {
el.addEventListener('click', timeTrack);
});
}
function localStorageSet(timeStamp, newNote) {
//create key based on current videoURL
//value will be object containing key/value pairs of timeStamp and newNote
localStore.setItem(`${vidURL}${timeStamp}`, `${newNote}`);
}
document
.querySelector('.notes-submit-btn')
.addEventListener('click', submitNote);
</script>
</body>
</html>