-
Notifications
You must be signed in to change notification settings - Fork 2
/
example-script.js
368 lines (231 loc) · 11.4 KB
/
example-script.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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
function getMovieSuggestions() {
const movieName = document.getElementById('movieName').value;
const apiKey = 'your-tmdb-api-key'; // Replace with your TMDb API key
if (movieName.trim() === '') {
clearMovieSuggestions();
return;
}
// Make a request to TMDb API for movie suggestions
fetch(`https://api.themoviedb.org/3/search/movie?api_key=${apiKey}&query=${encodeURIComponent(movieName)}`)
.then(response => response.json())
.then(data => {
const movieSuggestionsList = document.getElementById('movieSuggestions');
movieSuggestionsList.innerHTML = '';
if (data.results && data.results.length > 0) {
data.results.slice(0, 5).forEach(result => {
const listItem = document.createElement('li');
listItem.textContent = result.title;
listItem.onclick = function () {
document.getElementById('movieName').value = result.title;
clearMovieSuggestions();
};
movieSuggestionsList.appendChild(listItem);
});
}
})
.catch(error => {
console.error('Error fetching movie suggestions:', error);
clearMovieSuggestions();
});
}
function searchMovie() {
const movieName = document.getElementById('movieName').value;
const apiKey = 'your-tmdb-api-key'; // Replace with your TMDb API key
// Make a request to TMDb API for movie details
fetch(`https://api.themoviedb.org/3/search/movie?api_key=${apiKey}&query=${encodeURIComponent(movieName)}`)
.then(response => response.json())
.then(data => {
const movieResultElement = document.getElementById('movieResult');
const movieCopyButton = document.getElementById('movieCopyButton');
if (data.results && data.results.length > 0) {
const movieTmdbId = data.results[0].id;
// Construct the URL for embedding the first movie
const firstMovieUrl = `https://vidsrc.xyz/embed/movie/${movieTmdbId}`;
// Construct the URL for embedding the second movie
const secondMovieUrl = `https://vidsrc.to/embed/movie/${movieTmdbId}`;
// Create the first iframe element
const firstIframe = document.createElement('iframe');
firstIframe.src = firstMovieUrl;
firstIframe.allowfullscreen = true;
// Create the second iframe element
const secondIframe = document.createElement('iframe');
secondIframe.src = secondMovieUrl;
secondIframe.allowfullscreen = true;
// Clear previous content
movieResultElement.innerHTML = '';
// Display the generated URLs as clickable links
const firstLinkElement = document.createElement('a');
firstLinkElement.href = firstMovieUrl;
firstLinkElement.target = '_blank';
firstLinkElement.textContent = "Generated URL 1: " + firstMovieUrl;
const secondLinkElement = document.createElement('a');
secondLinkElement.href = secondMovieUrl;
secondLinkElement.target = '_blank';
secondLinkElement.textContent = "Generated URL 2: " + secondMovieUrl;
// Append the links and iframes to the result element
movieResultElement.appendChild(firstLinkElement);
movieResultElement.appendChild(firstIframe);
movieResultElement.appendChild(document.createElement('br')); // Add a line break
movieResultElement.appendChild(secondLinkElement);
movieResultElement.appendChild(secondIframe);
// Enable the copy button for the movies
movieCopyButton.disabled = false;
// Store the URLs for the movies in global variables for copying
window.generatedFirstMovieUrl = firstMovieUrl;
window.generatedSecondMovieUrl = secondMovieUrl;
} else {
movieResultElement.innerHTML = 'Movie not found';
// Disable the copy button for the movies if no movie is found
movieCopyButton.disabled = true;
}
})
.catch(error => {
console.error('Error fetching movie data:', error);
document.getElementById('movieResult').innerHTML = 'Error fetching movie data';
// Disable the copy button for the movies in case of an error
document.getElementById('movieCopyButton').disabled = true;
});
}
function copyMovieToClipboard() {
const generatedMovieUrl = window.generatedMovieUrl;
if (!generatedMovieUrl) {
console.error('No generated movie URL to copy.');
return;
}
// Create a temporary textarea element
const textarea = document.createElement('textarea');
textarea.value = generatedMovieUrl;
// Append it to the body
document.body.appendChild(textarea);
// Select the text
textarea.select();
try {
// Use the Clipboard API to copy the text to the clipboard
document.execCommand('copy');
console.log('URL copied to clipboard:', generatedMovieUrl);
} catch (error) {
console.error('Error copying to clipboard:', error);
} finally {
// Remove the temporary textarea
document.body.removeChild(textarea);
}
}
function clearMovieSuggestions() {
document.getElementById('movieSuggestions').innerHTML = '';
}
// Series Section
function getSeriesSuggestions() {
const seriesName = document.getElementById('seriesName').value;
const apiKey = 'your-tmdb-api-key'; // Replace with your TMDb API key
if (seriesName.trim() === '') {
clearSeriesSuggestions();
return;
}
// Make a request to TMDb API for series suggestions
fetch(`https://api.themoviedb.org/3/search/tv?api_key=${apiKey}&query=${encodeURIComponent(seriesName)}`)
.then(response => response.json())
.then(data => {
const seriesSuggestionsList = document.getElementById('seriesSuggestions');
seriesSuggestionsList.innerHTML = '';
if (data.results && data.results.length > 0) {
data.results.slice(0, 5).forEach(result => {
const listItem = document.createElement('li');
listItem.textContent = result.name;
listItem.onclick = function () {
document.getElementById('seriesName').value = result.name;
clearSeriesSuggestions();
};
seriesSuggestionsList.appendChild(listItem);
});
}
})
.catch(error => {
console.error('Error fetching series suggestions:', error);
clearSeriesSuggestions();
});
}
function searchSeries() {
const seriesName = document.getElementById('seriesName').value;
const apiKey = 'your-tmdb-api-key'; // Replace with your TMDb API key
// Make a request to TMDb API for series details
fetch(`https://api.themoviedb.org/3/search/tv?api_key=${apiKey}&query=${encodeURIComponent(seriesName)}`)
.then(response => response.json())
.then(data => {
const seriesResultElement = document.getElementById('seriesResult');
const seriesCopyButton = document.getElementById('seriesCopyButton');
if (data.results && data.results.length > 0) {
const seriesTmdbId = data.results[0].id;
// Construct the URL for embedding the first series
const firstSeriesUrl = `https://vidsrc.xyz/embed/tv/${seriesTmdbId}`;
// Construct the URL for embedding the second series
const secondSeriesUrl = `https://vidsrc.to/embed/tv/${seriesTmdbId}`;
// Create the first iframe element
const firstIframe = document.createElement('iframe');
firstIframe.src = firstSeriesUrl;
firstIframe.allowfullscreen = true;
// Create the second iframe element
const secondIframe = document.createElement('iframe');
secondIframe.src = secondSeriesUrl;
secondIframe.allowfullscreen = true;
// Clear previous content
seriesResultElement.innerHTML = '';
// Display the generated URLs as clickable links
const firstLinkElement = document.createElement('a');
firstLinkElement.href = firstSeriesUrl;
firstLinkElement.target = '_blank';
firstLinkElement.textContent = 'Generated URL 1: ' + firstSeriesUrl;
const secondLinkElement = document.createElement('a');
secondLinkElement.href = secondSeriesUrl;
secondLinkElement.target = '_blank';
secondLinkElement.textContent = 'Generated URL 2: ' + secondSeriesUrl;
// Append the links and iframes to the result element
seriesResultElement.appendChild(firstLinkElement);
seriesResultElement.appendChild(firstIframe);
seriesResultElement.appendChild(document.createElement('br')); // Add a line break
seriesResultElement.appendChild(secondLinkElement);
seriesResultElement.appendChild(secondIframe);
// Enable the copy button for the series
seriesCopyButton.disabled = false;
// Store the URLs for the series in global variables for copying
window.generatedFirstSeriesUrl = firstSeriesUrl;
window.generatedSecondSeriesUrl = secondSeriesUrl;
} else {
seriesResultElement.innerHTML = 'Series not found';
// Disable the copy button for the series if no series is found
seriesCopyButton.disabled = true;
}
})
.catch(error => {
console.error('Error fetching series data:', error);
document.getElementById('seriesResult').innerHTML = 'Error fetching series data';
// Disable the copy button for the series in case of an error
document.getElementById('seriesCopyButton').disabled = true;
});
}
function copySeriesToClipboard() {
const generatedSeriesUrl = window.generatedSeriesUrl;
if (!generatedSeriesUrl) {
console.error('No generated series URL to copy.');
return;
}
// Create a temporary textarea element
const textarea = document.createElement('textarea');
textarea.value = generatedSeriesUrl;
// Append it to the body
document.body.appendChild(textarea);
// Select the text
textarea.select();
try {
// Use the Clipboard API to copy the text to the clipboard
document.execCommand('copy');
console.log('URL copied to clipboard:', generatedSeriesUrl);
} catch (error) {
console.error('Error copying to clipboard:', error);
} finally {
// Remove the temporary textarea
document.body.removeChild(textarea);
}
}
function clearSeriesSuggestions() {
document.getElementById('seriesSuggestions').innerHTML = '';
}