Video Auto Pause After The Tab Hides
// ==UserScript==
// @name 切出窗口自动暂停视频(Video Auto Pause After The Tab Hides)
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Video Auto Pause After The Tab Hides
// @author poco
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant none
// @license GNU GPLv3
// @noframes
// ==/UserScript==
(function() {
if(document.domain.includes("huya.com")){
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
let pauseBtn = document.querySelector('.player-pause-btn')
if(pauseBtn){
pauseBtn.click()
}
}
})
}else {
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
let videoDom = document.querySelector('video')
if(videoDom){
videoDom.pause()
}
}
})
}
})();