Pause videos playing in background tabs when a video starts playing in the foreground tab
目前為
// ==UserScript==
// @name Autopause video
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Pause videos playing in background tabs when a video starts playing in the foreground tab
// @author Kirill Skliarov
// @match *://*/*
// @license MIT
// @grant none
// ==/UserScript==
(function() {
'use strict';
const video = document.querySelector('video');
if (video) {
const channel = new BroadcastChannel('AutoPauseVideoInBackgroundTabs');
video.addEventListener('play', () => channel.postMessage(null));
channel.addEventListener('message', () => video.pause());
}
})();