h1 動画アップロード = render 'resizing/rails/videos/upload_form' = paginate(@videos) .row.row-cols-1.row-cols-md-4.g-3 - @videos.each do |video| .col .card.h-100 data-video-url=video.data_self_url img.js-video-thumbnail.card-img-top .card-body h5.card-title = "#{video.id}:#{video.data_id}" ul.list-group.list-group-flush li.list-group-item | State: span.video-state = video.data_state li.list-group-item | AVC a.card-link.avc-url.data-copy-url href='#' | Copy URL li.list-group-item | HEVC a.card-link.hevc-url.data-copy-url href='#' | Copy URL .card-footer small.text-muted = 'asfadf' .card-body = link_to 'Show video details', video, class: 'btn btn-primary' = paginate(@videos) javascript: document.addEventListener('DOMContentLoaded', ()=> { let setDataCopyURLOrRemoveElement = (elem, value) => { if(value) { elem.setAttribute('data-copy-url', value) } else { elem.remove() } } elements = document.querySelectorAll('[data-video-url]') elements.forEach(elem => { url = elem.getAttribute('data-video-url') fetcher = new Resizing.Rails.VideoFetcher(url) fetcher.fetch().then(data => { elem.querySelector('.js-video-thumbnail').setAttribute('src', data.thumbnail_url) elem.querySelector('.video-state').textContent = data.state setDataCopyURLOrRemoveElement(elem.querySelector('.avc-url'), data.avc_url) setDataCopyURLOrRemoveElement(elem.querySelector('.hevc-url'), data.hevc_url) }) }) })