(function () {
function getVideo() {
return document.querySelector('.jr-hero .jr-hero-video');
}
function lockLastFrame(v) {
// Ensure no looping
v.loop = false;
v.removeAttribute('loop');
// If already ended (can happen with cached/autoplay), lock immediately
if (v.ended) {
try { v.currentTime = Math.max(0, (v.duration || 0) - 0.05); } catch (e) {}
try { v.pause(); } catch (e) {}
return;
}
// Bind once
if (!v.__jrBound) {
v.__jrBound = true;
v.addEventListener('ended', function () {
// Seek to just before the end to guarantee a drawable frame
try { v.currentTime = Math.max(0, (v.duration || 0) - 0.05); } catch (e) {}
// Pause after the seek resolves
setTimeout(function () {
try { v.pause(); } catch (e) {}
}, 80);
});
// Safety: if the browser fires pause at end without ended (rare)
v.addEventListener('timeupdate', function () {
if (!v.duration) return;
if (v.currentTime >= v.duration - 0.02) {
try { v.pause(); } catch (e) {}
}
});
}
}
function apply() {
var v = getVideo();
if (!v) return;
// Slow down (keep if you want)
try { v.playbackRate = 0.5; } catch (e) {}
lockLastFrame(v);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', apply);
} else {
apply();
}
window.addEventListener('load', apply);
// Reapply because some browsers reset playbackRate/loop after autoplay starts
setTimeout(apply, 300);
setTimeout(apply, 1200);
// If the page builder swaps/rehydrates nodes, retry a few times
var tries = 0;
var iv = setInterval(function () {
tries += 1;
apply();
if (tries >= 10) clearInterval(iv);
}, 500);
})();