STOP MEDIA!

Stops media playback when the player leaves the visible screen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         STOP MEDIA!
// @namespace    vamonos.stop.media
// @version      1.0
// @description  Stops media playback when the player leaves the visible screen.
// @author       V4M0N0S
// @license      MIT
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    window.addEventListener('scroll', function() {
        var mediaElements = document.querySelectorAll('video, audio');
        mediaElements.forEach(function(mediaElement) {
            var rect = mediaElement.getBoundingClientRect();
            if (rect.bottom < 0 || rect.top > window.innerHeight) {
                mediaElement.pause();
            }
        });
    });
})();