PageSourceSearch

https://spacewaves2.net/template/default/js/youtube-lazy.js

js spacewaves2.net collected 2026-09-26 03:39:27 UTC 2,465 bytes, 61 lines download raw bytes

1(function () {
2    var placeholders = document.querySelectorAll('.video-lazy-placeholder');
3    if (!placeholders.length) return;
4
5    function loadThumb(placeholder) {
6        if (placeholder.dataset.thumbLoaded === '1') return;
7        var videoId = placeholder.getAttribute('data-video-id');
8        var img = placeholder.querySelector('.video-card__thumb');
9        if (!videoId || !img) return;
10        img.src = 'https://i.ytimg.com/vi/' + videoId + '/hqdefault.jpg';
11        placeholder.dataset.thumbLoaded = '1';
12        placeholder.classList.add('is-ready');
13    }
14
15    function playVideo(placeholder) {
16        var wrap = placeholder.closest('.video-card__media');
17        if (!wrap || wrap.dataset.playing === '1') return;
18        var videoId = placeholder.getAttribute('data-video-id');
19        if (!videoId) return;
20        var title = placeholder.getAttribute('aria-label') || 'YouTube video';
21        var iframe = document.createElement('iframe');
22        iframe.setAttribute('src', 'https://www.youtube.com/embed/' + videoId + '?autoplay=1&rel=0');
23        iframe.setAttribute('title', title);
24        iframe.setAttribute('loading', 'lazy');
25        iframe.setAttribute('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share');
26        iframe.setAttribute('allowfullscreen', '');
27        iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
28        wrap.dataset.playing = '1';
29        wrap.classList.add('is-playing');
30        wrap.appendChild(iframe);
31        placeholder.remove();
32    }
33
34    placeholders.forEach(function (placeholder) {
35        placeholder.addEventListener('click', function () { playVideo(placeholder); });
36        placeholder.addEventListener('keydown', function (e) {
37            if (e.key === 'Enter' || e.key === ' ') {
38                e.preventDefault();
39                playVideo(placeholder);
40            }
41        });
42    });
43
44    if (!('IntersectionObserver' in window)) {
45        placeholders.forEach(loadThumb);
46        return;
47    }
48
49    var observer = new IntersectionObserver(function (entries) {
50        entries.forEach(function (entry) {
51            if (entry.isIntersecting) {
52                loadThumb(entry.target);
53                observer.unobserve(entry.target);
54            }
55        });
56    }, { rootMargin: '160px 0px' });
57
58    placeholders.forEach(function (placeholder) {
59        observer.observe(placeholder);
60    });
61})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.