Substack: auto-pause embedded videos
Pauses HTML5 videos and disables autoplay on embedded YouTube/Vimeo so media does not start on its own.
Code to copy
// Auto-pause embedded video previews so they do not autoplay inside posts
(function () {
function pause() {
document.querySelectorAll('video').forEach(function (v) {
if (v.dataset.jzPaused) { return; }
v.dataset.jzPaused = '1';
try { v.autoplay = false; v.removeAttribute('autoplay'); v.pause(); } catch (e) {}
});
document.querySelectorAll('iframe[src*="youtube.com/embed"], iframe[src*="player.vimeo.com"]').forEach(function (f) {
if (f.dataset.jzPaused) { return; }
var src = f.getAttribute('src') || '';
if (/(\?|&)autoplay=1/i.test(src)) {
f.setAttribute('src', src.replace(/(\?|&)autoplay=1/i, function (m) { return m.charAt(0) + 'autoplay=0'; }));
}
f.dataset.jzPaused = '1';
});
}
pause();
var obs = new MutationObserver(function () {
clearTimeout(window.__jzSubPause);
window.__jzSubPause = setTimeout(pause, 300);
});
obs.observe(document.body, { childList: true, subtree: true });
})();
How to use this example
- Copy the code with the button above.
- Install JustZix (2 minutes) and open the extension on the target page.
- Add a new rule matching that page.
- Paste the code into the rule's JavaScript panel and save — it runs on every page visit.
Rate this example
No ratings yet — be the first.