-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
234 lines (227 loc) · 11.7 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
<html>
<head>
<title>Cari text | Vue Fundamental</title>
</head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/v4-shims.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.1/css/bootstrap.min.css" integrity="sha384-VCmXjywReHh4PwowAiWNagnWcLhlEJLA5buUprzK8rxFgeH0kww/aWY76TfkUoSX" crossorigin="anonymous">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/css-spinning-spinners/1.1.0/load5.css" />
<link rel="stylesheet" href="index.css">
<body>
<div id="app" class="container h-100 mh-100 overflow-auto app">
<!-- navbar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<span class="fas fa-search navbar-brand"></span> <a class="navbar-brand font-weight-bold" href="#">Cari Teks App </a>
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
</ul>
<span class="navbar-brand">by <a style="color: yellow;" href="https://www.linkedin.com/in/devid-runtuwene-b623a7123/">Devid</a></span>
</nav>
<!-- navbar -->
<!-- section input -->
<section class="section-form">
<div class="container">
<div class="form-group mt-5">
<center><label>Link youtube</label></center>
<input type="text" class="form-control form-control-lg text-center" placeholder="Contoh:https://www.youtube.com/watch?v=klnvttPfOUM" v-model="url" >
</div>
<div class="col-auto">
<center><label>Kata kunci</label></center>
<div class="input-group">
<input type="text" class="form-control form-control-lg text-center" placeholder="Cari kata" v-model="query" :disabled="!url">
</div>
</div>
</section>
<!-- section input -->
<!-- section control -->
<section class="section-control mt-5">
<div class="container">
<button @click="clearAllResultAndPagination" class="btn btn-danger fa-pull-right" :disabled="!query"><span class="fas fa-trash navbar-brand"></span>Hapus kata kunci</button>
<div class="row">
<div class="custom-control custom-checkbox" v-if="data.length>0">
<input type="checkbox" class="custom-control-input" id="customCheck2" v-model="isPaginated" true-value="1" false-value='0'>
<label class="custom-control-label" for="customCheck2">Gunakan Paginasi</label>
</div>
<div v-if="isPaginated==1">
<div class="mb-5">
<button @click="navigate('first')" :disabled="!pagination.first" class="btn btn-warning"><span class="fas fa-home"></span> Awal</button>
<button @click="navigate('prev')" :disabled="!pagination.prev" class="btn btn-warning"><span class="fas fa-chevron-circle-left"></span> Sebelumnya</button>
<button @click="navigate('next')" :disabled="!pagination.next" class="btn btn-warning"><span class="fas fa-chevron-circle-right"></span> Selanjutnya</button>
<button @click="navigate('last')" :disabled="!pagination.last" class="btn btn-warning"><span class="fas fa-step-forward"></span> Akhir</button>
</div>
</div>
</div>
<div class="container">
<div class="row" v-if="isPaginated==1">
<div class="custom-control custom-checkbox" v-if="data.length>0" checked>
<input type="checkbox" v-model="isMarked" class="custom-control-input" id="customCheck1" true-value="1" false-value='0'>
<label class="custom-control-label" for="customCheck1">Gunakan Sorotan</label>
</div>
<div class="mb-5 input-group col-4 " v-if="data.length>0">
<label>Tampilkan</label>
<select class="custom-select " v-model="pagination.size">
<option v-for="items in providedSize" :value="items">{{items}}</option>
</select>
<label>Data</label>
</div>
</div>
</div>
</div>
<br>
<div class="mt-5" v-if="data.length>0">
<h4 class="the-result fa-pull-right">Total Hasil Pencarian: {{ pagination.total ? pagination.total : '-'}}</h4>
<h4 class="the result fa-pull-left" v-show="isPaginated==1">Halaman ke: {{ pagination.page ? pagination.page : '-'}}</h4>
</div>
<br>
</section>
<!-- section control -->
<!-- section result -->
<section>
<div class="loading" v-if="isRequesting"></div>
<div class="section-list">
<div class="mt-5">
<ul>
<li class="list-data" v-for="dataTranscript in data">
<span v-html="dataTranscript.text"></span>
<a :href="`${url}&t=${dataTranscript.start}`" class="btn btn-secondary">Youtube</a>
</li>
<br>
</ul>
</div>
</div>
</section>
<!-- section result -->
</div>
</body>
<!-- production version, optimized for size and speed -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<!-- debouncer -->
<script src="debounce.js"></script>
<!-- vue code -->
<script>
var app = new Vue({
el: '#app',
data: {
query: '',
url: '',
data: [],
isRequesting: false,
isPaginated: 0,
isMarked: 1,
providedSize: [5,10,15,20,25],
pagination: {
prev: null,
next: null,
total: 0,
first: null,
last: null,
page: null,
size: null,
}
},
watch:{
url: function (recentUrl,prevUrl){
if(!this.isValidURL(recentUrl)) this.clearAllResultAndPagination()
},
query: pDebounce(async function handleQuery(query) {
if (query && query.length >= 3) {
await this.callAPI()
} else{
if(query){
this.data = []
}
this.clearAllResultAndPagination()
}
}, 400),
isPaginated: function(){
if(this.query)this.callAPI()
},
isMarked: function(){
if(this.data.length > 0) this.callAPI()
},
'pagination.size': function(){
if(this.pagination.size) this.callAPI()
}
},
methods:{
isValidURL(str){
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
return !!pattern.test(str);
},
callAPI: async function(optional_url){
this.isRequesting = true
//Append custom params
let params = []
//Use or not use highlight
if(this.isMarked) await params.push(`&marked=${this.isMarked}`)
//Use page size
if(this.pagination.size>0) await params.push(`&size=${this.pagination.size}`)
params.push(`&paginated=${this.isPaginated}`)
let api_url = ''
if(!optional_url) api_url = `https://cari-teks-video-api.vercel.app/api/search?url=${encodeURIComponent(this.url)}&q=${this.query}${await params.join("")}`
else api_url = optional_url
if(this.isValidURL(this.url)){
try{
const response = await fetch(api_url).then(res=> res.ok ? res.json() : [])
this.data=response.output ? [] : response.data
this.pagination.total = response.total || response.data.length
this.pagination.first = response.first
this.pagination.last = response.last
this.pagination.next = response.next
this.pagination.prev = response.prev
this.pagination.page = response.page
this.isRequesting = false
if(response.output) alert("Something error. try again")
}
catch(err){
this.isRequesting = false
alert("Something error try again")
}
}
else{
this.isRequesting = false
alert("URL not valid please input other URL")
}
},
navigate: function(type){
switch(type){
case 'next':
this.callAPI(this.pagination.next)
break;
case 'prev':
this.callAPI(this.pagination.prev)
break;
case 'last':
this.callAPI(this.pagination.last)
break;
case 'first':
this.callAPI(this.pagination.first)
break;
}
},
clearAllResultAndPagination : function(){
this.query = ''
this.data = [],
this.isPaginated = 0
this.isMarked = 1
this.pagination.prev = null
this.pagination.next = null
this.pagination.total = 0
this.pagination.first = null
this.pagination.last = null
this.pagination.page = null
this.pagination.size = null
this.isRequesting = false
}
}
})
</script>
</html>