Advertisement
Guest User

codesource

a guest
Jul 4th, 2024
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.64 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <link rel="stylesheet" href="../style.css">
  7.     <title>V2 - FightStreaming</title>
  8. </head>
  9. <body>
  10.     <div class="Container">
  11.         <header>
  12.             <div class="Entete">
  13.                 <div class="LogoTitle">
  14.                     <a href="../index.html">
  15.                         <h1>FightStreaming</h1>
  16.                     </a>
  17.                 </div>
  18.                 <div class="SearchBar">
  19.                     <form>
  20.                         <input type="search" placeholder="Recherche..." id="searchFight">
  21.                     </form>
  22.                 </div>
  23.                 <div class="searchBarResponsive">
  24.                     <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="28" height="28" color="#000000" fill="none">
  25.                         <path d="M17.5 17.5L22 22" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
  26.                         <path d="M20 11C20 6.02944 15.9706 2 11 2C6.02944 2 2 6.02944 2 11C2 15.9706 6.02944 20 11 20C15.9706 20 20 15.9706 20 11Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" />
  27.                     </svg>
  28.                 </div>
  29.             </div>
  30.         </header>
  31.         <main>
  32.             <section class="section-3">
  33.                 <div class="row-3">
  34.                     <div class="col-3">
  35.                         <div class="WatchFight">
  36.                             <div class="Item-WatchFight">
  37.                                 <h1 id="event-name"></h1>
  38.                                 <iframe id="event-video" src="" frameborder="0" allowfullscreen></iframe>
  39.                             </div>
  40.                             <div class="FightCard" id="fight-card">
  41.                                 <!-- Les éléments de fightCard seront insérés ici -->
  42.                             </div>
  43.                         </div>
  44.                     </div>
  45.                 </div>
  46.             </section>
  47.         </main>
  48.     </div>
  49.     <script>
  50.         document.addEventListener('DOMContentLoaded', function() {
  51.             // Fonction pour obtenir les paramètres de l'URL
  52.             function getQueryParams() {
  53.                 const params = {};
  54.                 const queryString = window.location.search.substring(1);
  55.                 const regex = /([^&=]+)=([^&]*)/g;
  56.                 let m;
  57.                 while (m = regex.exec(queryString)) {
  58.                     params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
  59.                 }
  60.                 return params;
  61.             }
  62.  
  63.             const params = getQueryParams();
  64.             const eventName = params.eventName;
  65.             const eventId = params.eventId;
  66.  
  67.             // Mettre à jour le titre de l'événement
  68.             if (eventName) {
  69.                 document.getElementById('event-name').innerText = eventName;
  70.             }
  71.  
  72.             // Récupérer les données fightCard de localStorage
  73.             const fightCard = eventId ? JSON.parse(localStorage.getItem(eventId)) : [];
  74.  
  75.             // Vérifier que fightCard est un tableau
  76.             if (Array.isArray(fightCard) && fightCard.length > 0) {
  77.                const fightCardContainer = document.getElementById('fight-card');
  78.                 const eventVideo = document.getElementById('event-video');
  79.  
  80.                 // Afficher la première vidéo par défaut
  81.                 eventVideo.src = fightCard[0].videos[0];
  82.  
  83.                 fightCard.forEach((fight, index) => {
  84.                     const fightItem = document.createElement('div');
  85.                     fightItem.className = 'item-fightCard';
  86.                     fightItem.innerHTML = `
  87.                         <h1 class="fight-title">
  88.                             <a href="#" class="video-link" data-video="${fight.videos[0]}">${fight.name}</a>
  89.                         </h1>
  90.                     `;
  91.                     fightCardContainer.appendChild(fightItem);
  92.                 });
  93.  
  94.                 // Ajouter un gestionnaire d'événements pour chaque lien vidéo
  95.                 document.querySelectorAll('.video-link').forEach(link => {
  96.                     link.addEventListener('click', function(event) {
  97.                         event.preventDefault();
  98.                         // Mettre à jour l'iframe principale avec la vidéo du lien cliqué
  99.                         eventVideo.src = this.getAttribute('data-video');
  100.                     });
  101.                 });
  102.             } else {
  103.                 console.error('fightCard est vide ou non défini');
  104.             }
  105.         });
  106.     </script>
  107. </body>
  108. </html>
  109.  
  110.  
  111.  
  112. JAVASCRIPT:
  113.  
  114.  
  115. const url = 'http://...';
  116.  
  117. fetch(url)
  118. .then(response => {
  119.     return response.json();
  120. })
  121. .then(data => {
  122.     console.log(data);
  123.  
  124.     const UFC_Fights = document.querySelector('.Fights');
  125.  
  126.     // Accéder uniquement aux index 0 et 2
  127.     const indices = [0, 2];
  128.     indices.forEach(index => {
  129.         const promotion = data[index];
  130.         if (promotion && Array.isArray(promotion.events)) {
  131.            promotion.events.forEach(event => {
  132.                const item_UFC_Fights = document.createElement('div');
  133.                 item_UFC_Fights.className = 'item-Fights';
  134.  
  135.                 // Générer un identifiant unique pour chaque événement
  136.                 const eventId = `event-${index}-${event.eventName.replace(/\s+/g, '-')}`;
  137.  
  138.                 // Ajouter plusieurs liens vidéo aux données de fightCard
  139.                 const fightCardWithVideos = event.fightCard.map((fight, i) => ({
  140.                     name: fight,
  141.                     videos: [
  142.                         `https://youtu.be/embed/mzO5mL2kgEo?si=Smr2AVGj2U1YTEFB&index=${i}`,
  143.                        `https://youtu.be/DBn_dS04kMY?si=f9u91vfWn9VJeK5o&index=${i}`
  144.                    ]
  145.                }));
  146.  
  147.                 // Stocker les données dans localStorage
  148.                 localStorage.setItem(eventId, JSON.stringify(fightCardWithVideos));
  149.  
  150.                 item_UFC_Fights.innerHTML = `
  151.                 <a href="./boxingmatch.html?eventName=${encodeURIComponent(event.eventName)}&eventId=${eventId}">
  152.                     <img src="${event.imgURL}" alt="${event.eventName}">
  153.                     <div class="Title-item-Fights">
  154.                         <h1>${event.eventName}</h1>
  155.                         <p>${event.eventDate}</p>
  156.                     </div>
  157.                 </a>
  158.                 `;
  159.                 UFC_Fights.appendChild(item_UFC_Fights);
  160.             });
  161.         }
  162.     });
  163. })
  164. .catch(error => {
  165.     console.error('Error fetching data:', error);
  166. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement