Advertisement
MizunoBrasil

youtube embed 2

Jan 21st, 2025
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.50 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pt-BR">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Postagem Simplificada</title>
  7.     <!-- Bootstrap CSS -->
  8.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  9.     <style>
  10.         body {
  11.             font-family: Helvetica, Arial, sans-serif;
  12.             font-size: 14px;
  13.         }
  14.  
  15.         .container {
  16.             max-width: 800px;
  17.             margin: 0 auto;
  18.             padding: 20px;
  19.         }
  20.  
  21.         form {
  22.             display: grid;
  23.             gap: 10px;
  24.         }
  25.     </style>
  26. </head>
  27. <body>
  28.  
  29. <div class="container">
  30.     <h2>Youtube Video Embed</h2>
  31.     <form>
  32.         <div class="form-group">
  33.             <label for="observacao">Codigo html embed gerado</label>
  34.             <textarea class="form-control" id="observacao" name="observacao" style="height: 200px;" required></textarea>
  35.         </div>
  36.  
  37.         <div class="form-group">
  38.             <label for="youtube_url">URL do YouTube:</label>
  39.             <div class="input-group">
  40.                 <input type="text" class="form-control" id="youtube_url" placeholder="Insira a URL do vídeo do YouTube">
  41.                 <div class="input-group-append">
  42.                     <button type="button" class="btn btn-secondary" id="gerar_embed">Gerar Embed YouTube</button>
  43.                 </div>
  44.             </div>
  45.         </div>
  46.  
  47.         <div class="form-group" id="video_container" style="display: none;">
  48.             <h4>Vídeo Embedado:</h4>
  49.             <div id="video_embed"></div>
  50.         </div>
  51.     </form>
  52. </div>
  53.  
  54. <!-- Bootstrap JS and dependencies -->
  55. <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
  56. <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@1.16.1/dist/umd/popper.min.js"></script>
  57. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
  58. <script>
  59.     document.getElementById('gerar_embed').addEventListener('click', function () {
  60.         const youtubeUrl = document.getElementById('youtube_url').value;
  61.         const observacao = document.getElementById('observacao');
  62.         const videoContainer = document.getElementById('video_container');
  63.         const videoEmbed = document.getElementById('video_embed');
  64.  
  65.         if (youtubeUrl) {
  66.             // Extrair o ID do vídeo do YouTube
  67.             const videoId = youtubeUrl.split('v=')[1]?.split('&')[0] || youtubeUrl.split('/').pop();
  68.  
  69.             if (videoId) {
  70.                 // Gerar o código embed
  71.                 const embedCode = `<div style="left: 0; width: 100%; height: 0; position: relative; padding-bottom: 56.25%;"><iframe style="top: 0; left: 0; width: 100%; height: 100%; position: absolute; border: 0;" src="https://www.youtube.com/embed/${videoId}?rel=0" scrolling="no" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share;" allowfullscreen="allowfullscreen"></iframe></div>`;
  72.  
  73.                 // Inserir no campo de observação
  74.                 observacao.value += embedCode;
  75.  
  76.                 // Mostrar o vídeo embedado
  77.                 videoEmbed.innerHTML = embedCode;
  78.                 videoContainer.style.display = 'block';
  79.             } else {
  80.                 alert('URL inválida. Por favor, insira uma URL válida do YouTube.');
  81.             }
  82.         } else {
  83.             alert('Por favor, insira a URL do vídeo do YouTube.');
  84.         }
  85.     });
  86. </script>
  87. </body>
  88. </html>
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement