mmsubandmovies commited on
Commit
f7f4c16
1 Parent(s): 7bf0dc7

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +65 -0
script.js ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.addEventListener('DOMContentLoaded', function () {
2
+ // Proxy URL to bypass CORS policy
3
+ const proxyURL = 'https://api.allorigins.win/get?url=';
4
+ const playlistURL = 'https://github.com/byte-capsule/FanCode-Hls-Fetcher/blob/main/Fancode_Live.m3u?raw=true';
5
+ const proxyPlaylistURL = proxyURL + encodeURIComponent(playlistURL);
6
+
7
+ fetch(proxyPlaylistURL)
8
+ .then(response => response.json())
9
+ .then(data => {
10
+ const playlistContent = data.contents;
11
+ const playlist = document.getElementById('playlist');
12
+ const lines = playlistContent.split('\n');
13
+ let firstStreamUrl = null;
14
+ lines.forEach((line, index) => {
15
+ if (line.startsWith('#EXTINF')) {
16
+ const title = line.split(',')[1];
17
+ const url = lines[index + 1].trim();
18
+ const listItem = document.createElement('li');
19
+ listItem.className = 'list-group-item';
20
+ listItem.innerHTML = `<a href="#" data-url="${url}">${title}</a>`;
21
+ playlist.appendChild(listItem);
22
+
23
+ // Set the first stream URL
24
+ if (firstStreamUrl === null) {
25
+ firstStreamUrl = url;
26
+ }
27
+ }
28
+ });
29
+
30
+ // Play the first stream by default
31
+ if (firstStreamUrl !== null) {
32
+ playStream(firstStreamUrl);
33
+ }
34
+
35
+ playlist.addEventListener('click', function (event) {
36
+ event.preventDefault();
37
+ if (event.target && event.target.nodeName === 'A') {
38
+ const streamUrl = event.target.getAttribute('data-url');
39
+ playStream(streamUrl);
40
+ }
41
+ });
42
+
43
+ // Hide the loading screen after at least 1 second
44
+ setTimeout(function () {
45
+ document.getElementById('loading-screen').style.display = 'none';
46
+ document.getElementById('content').style.display = 'block';
47
+ }, 1800); // 1800 milliseconds = 1 second
48
+ })
49
+ .catch(error => console.error('Error fetching the playlist:', error));
50
+
51
+ // Create a single instance of the player
52
+ const playerElement = document.getElementById('player');
53
+ const player = new Clappr.Player({
54
+ parentId: "#player",
55
+ width: '100%',
56
+ height: '100%',
57
+ autoPlay: true,
58
+ mediacontrol: {seekbar: "#bb86fc", buttons: "#e0e0e0"},
59
+ mute: false,
60
+ });
61
+
62
+ function playStream(url) {
63
+ player.load(url);
64
+ }
65
+ });