-
Notifications
You must be signed in to change notification settings - Fork 0
/
yt_test.html
86 lines (68 loc) · 2.52 KB
/
yt_test.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
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script type="text/javascript">
var add_counter = 0;
$(document).ready(function () {
$('#add_container').on('click', '.change_video', function() {
var id = $(this).data("id");
var new_link = $("#link_"+id).val();
var replacedUrl = new_link.replace(/\/watch\?v=/, '/embed/');
$("#yt_container").html("");
$("#yt_container").html('<iframe id="yt_video_link" width="560" height="315" src="'+replacedUrl+'" allowfullscreen></iframe>');
$("#now_watching").text(replacedUrl);
$("#watched_"+id).text("Watched");
addnew();
});
$('#add_container').on('click', '.remove_video', function() {
var id = $(this).data("id");
$("#div_"+id).remove();
});
$('.addnew').on('click', function (ev){
addnew();
});
var urlParams = new URLSearchParams(window.location.search);
var parameterValue = urlParams.get('v');
if (parameterValue != null)
{
addWithLink(parameterValue);
}
else
{
addnew();
}
function addnew(){
$('#add_container').append('<div id="div_'+add_counter+'"><input class="new_link" id = "link_'+add_counter+'" type="text"></input>' +
'<button data-id="'+add_counter+'" id = "add_'+add_counter+'" class="change_video">Change</button>' +
'<button data-id="'+add_counter+'" id = "remove_'+add_counter+'" class="remove_video">Remove</button><span id="watched_'+add_counter+'"></span></div>'
);
add_counter++;
}
function addWithLink(url){
$('#add_container').append('<div id="div_'+add_counter+'"><input class="new_link" id = "link_'+add_counter+'" type="text" value="https://www.youtube.com/watch?v='+url+'"></input>' +
'<button data-id="'+add_counter+'" id = "add_'+add_counter+'" class="change_video">Change</button>' +
'<button data-id="'+add_counter+'" id = "remove_'+add_counter+'" class="remove_video">Remove</button><span id="watched_'+add_counter+'"></span></div>'
);
autoStart(add_counter);
add_counter++;
}
function autoStart(id){
$('#add_'+id).click();
}
});
</script>
<style>
input{
width: 500px;
}
</style>
</head>
<div id="yt_container"></div>
<br>
Now watching:
<br>
<span id='now_watching'></span>
<br>
<button class ="addnew">Add new</button>
<div id="add_container"></div>
</html>