Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="pt-BR">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Postagem Simplificada</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
- <style>
- body {
- font-family: Helvetica, Arial, sans-serif;
- font-size: 14px;
- }
- .container {
- max-width: 800px;
- margin: 0 auto;
- padding: 20px;
- }
- form {
- display: grid;
- gap: 10px;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h2>Youtube Video Embed</h2>
- <form>
- <div class="form-group">
- <label for="observacao">Codigo html embed gerado</label>
- <textarea class="form-control" id="observacao" name="observacao" style="height: 200px;" required></textarea>
- </div>
- <div class="form-group">
- <label for="youtube_url">URL do YouTube:</label>
- <div class="input-group">
- <input type="text" class="form-control" id="youtube_url" placeholder="Insira a URL do vídeo do YouTube">
- <div class="input-group-append">
- <button type="button" class="btn btn-secondary" id="gerar_embed">Gerar Embed YouTube</button>
- </div>
- </div>
- </div>
- <div class="form-group" id="video_container" style="display: none;">
- <h4>Vídeo Embedado:</h4>
- <div id="video_embed"></div>
- </div>
- </form>
- </div>
- <!-- Bootstrap JS and dependencies -->
- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@1.16.1/dist/umd/popper.min.js"></script>
- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
- <script>
- document.getElementById('gerar_embed').addEventListener('click', function () {
- const youtubeUrl = document.getElementById('youtube_url').value;
- const observacao = document.getElementById('observacao');
- const videoContainer = document.getElementById('video_container');
- const videoEmbed = document.getElementById('video_embed');
- if (youtubeUrl) {
- // Extrair o ID do vídeo do YouTube
- const videoId = youtubeUrl.split('v=')[1]?.split('&')[0] || youtubeUrl.split('/').pop();
- if (videoId) {
- // Gerar o código embed
- 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>`;
- // Inserir no campo de observação
- observacao.value += embedCode;
- // Mostrar o vídeo embedado
- videoEmbed.innerHTML = embedCode;
- videoContainer.style.display = 'block';
- } else {
- alert('URL inválida. Por favor, insira uma URL válida do YouTube.');
- }
- } else {
- alert('Por favor, insira a URL do vídeo do YouTube.');
- }
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement