Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Codice html

  1. #1

    Codice html

    <!DOCTYPE html>
    <html lang="it">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>YouTube Breakfast&Match</title>
    <style>
    body {
    background-color: #ffffff;
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    color: #0077cc;
    }
    h1 {
    background-color: red;
    color: white;
    padding: 15px;
    text-align: center;
    text-transform: uppercase;
    font-size: 1.8em;
    margin: 0;
    font-weight: bold;
    }
    .section-title {
    color: #0077cc;
    font-size: 1.5em;
    margin: 20px 0 10px;
    text-align: center;
    font-weight: bold;
    }
    #contentSection, #barzaSection {
    text-align: center;
    margin-top: 20px;
    }
    iframe {
    margin-top: 10px;
    border: 2px solid #0077cc;
    border-radius: 10px;
    }
    </style>
    </head>
    <body>

    <h1>YouTube Breakfast&Match</h1>

    <div id="contentSection">
    <!-- Video del mattino -->
    </div>

    <div id="barzaSection">
    <!-- Video "Barza Pagelle" -->
    </div>

    <script>
    const channelId = "UC5lq4z_x_22UuH-b7rLmYBw";
    const rssFeedUrl = `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`;

    async function loadYouTubeContent() {
    try {
    const response = await fetch(rssFeedUrl);
    if (!response.ok) throw new Error("Errore nel caricamento del feed RSS.");

    const text = await response.text();
    const parser = new DOMParser();
    const xml = parser.parseFromString(text, "application/xml");
    const entries = xml.querySelectorAll("entry");

    if (entries.length === 0) throw new Error("Nessun video trovato nel feed RSS.");

    // Ordina i video cronologicamente (dal più recente al più vecchio)
    const sortedEntries = Array.from(entries).sort((a, b) => {
    const dateA = new Date(a.querySelector("published").textContent);
    const dateB = new Date(b.querySelector("published").textContent);
    return dateB - dateA;
    });

    let morningVideo = null;
    let barzaVideo = null;

    // Trova il video del mattino (fino alle 13:00)
    for (let i = 0; i < sortedEntries.length; i++) {
    const entry = sortedEntries[i];
    const title = entry.querySelector("title").textContent.toLowerCa se();
    const videoLink = entry.querySelector("link").getAttribute("href");
    const publishedDate = new Date(entry.querySelector("published").textContent) ;

    // Cerca il primo video del mattino
    if (!morningVideo && !title.includes("edizione straordinaria") && !title.includes("live reactions")) {
    if (publishedDate.getHours() < 13) {
    morningVideo = { title, videoLink, publishedDate };
    }
    }
    }

    // Trova l'ultimo video che contiene "Barza Pagelle" o "Pagelle"
    for (let i = 0; i < sortedEntries.length; i++) {
    const entry = sortedEntries[i];
    const title = entry.querySelector("title").textContent.toLowerCa se();
    const videoLink = entry.querySelector("link").getAttribute("href");

    // Cerca "Barza Pagelle" o "Pagelle" nel titolo
    if (title.includes("barza pagelle") || title.includes("pagelle")) {
    barzaVideo = { title, videoLink };
    break; // Prendi il primo video che trovi
    }
    }

    const now = new Date();
    let morningTitleText = "Oggi a Colazione";
    if (morningVideo && morningVideo.publishedDate.toDateString() !== now.toDateString()) {
    morningTitleText = "Ieri a Colazione";
    }

    // Mostra il video del mattino
    if (morningVideo) {
    const videoId = new URL(morningVideo.videoLink).searchParams.get("v");
    document.getElementById("contentSection").innerHTM L = `
    <div class="section-title">${morningTitleText}</div>
    <iframe width="300" height="170"
    src="https://www.youtube.com/embed/${videoId}"
    frameborder="0"
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
    allowfullscreen>
    </iframe>
    `;
    } else {
    document.getElementById("contentSection").innerHTM L = "<p>Nessun video disponibile per la mattina.</p>";
    }

    // Mostra il video che contiene "Barza Pagelle" o "Pagelle"
    if (barzaVideo) {
    const videoId = new URL(barzaVideo.videoLink).searchParams.get("v");
    document.getElementById("barzaSection").innerHTML = `
    <div class="section-title">Barza Pagelle dell'ultima partita</div>
    <iframe width="300" height="170"
    src="https://www.youtube.com/embed/${videoId}"
    frameborder="0"
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
    allowfullscreen>
    </iframe>
    `;
    } else {
    document.getElementById("barzaSection").innerHTML = "<p>Nessun video trovato con 'Barza Pagelle' o 'Pagelle'.</p>";
    }
    } catch (error) {
    console.error("Errore:", error.message);
    document.getElementById("contentSection").innerHTM L = "<p>Errore nel caricamento dei video.</p>";
    document.getElementById("barzaSection").innerHTML = "";
    }
    }

    loadYouTubeContent();
    </script>

    </body>
    </html>
    Secondo voi perché questo codice in una sezione di un app nativa funziona mentre in versione pwa da errore di caricamento?

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,444
    Ci sono diversi problemi con le modalità con cui hai aperto la discussione:

    1) non è la sezione adatta: meglio HTML oppure JavaScript;
    2) il titolo non è significativo;
    3) il codice non è formattato correttamente;
    4) non è indicato l'errore che ottieni nello specifico (dire "errore di caricamento" è un po' generico).

    Inoltre non possiamo prendere tutta l'applicazione e andarla a compilare, in due forme peraltro (app nativa e PWA) per diagnosticare il problema e suggerire una soluzione. Il codice è utile indicarlo - a patto di formattarlo - ma non si può affidare programma e problematica generica agli utenti del forum facendosela risolvere. Meglio aggiungere altri dettagli specifici con più precisione.

    L'invito è quindi di aprire una discussione nell'area corretta, aggiungendo le informazioni che mancano e chiarendo i dettagli segnalati che sono dubbi.

    Per questa e altre indicazioni, c'è il Regolamento di quest'area (oltre a quello generico del forum e dell'area di riferimento).

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

Tag per questa discussione

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.