Created
July 10, 2017 17:18
-
-
Save marktaiwan/6b110a0f861a0be86dea1ecb00594df9 to your computer and use it in GitHub Desktop.
Derpibooru WebM Pause in Background
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Derpibooru WebM Pause in Background | |
// @description Pauses background webms | |
// @version 0.0.1 | |
// @author Marker | |
// @namespace https://github.com/marktaiwan/ | |
// @updateURL https://openuserjs.org/meta/mark.taiwangmail.com/Derpibooru_WebM_Volume_Toggle.meta.js | |
// @match https://derpibooru.org/* | |
// @match https://trixiebooru.org/* | |
// @match https://www.derpibooru.org/* | |
// @match https://www.trixiebooru.org/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function pauseAll(list) { | |
for (let video of list) video.pause(); | |
} | |
function playAll(list) { | |
for (let video of list) video.play(); | |
} | |
function pauseReportVideo() { | |
var reportButton = document.querySelector('#duplicate_reporting label'); | |
var videos = document.querySelectorAll('#duplicate_reporting video'); | |
if (videos.length <= 0) { | |
return; | |
} | |
for (let ele of videos) { | |
ele.classList.add('videoReportThumb'); | |
} | |
pauseAll(videos); | |
reportButton.dataset.thumbnailVisibility = 'hidden'; | |
reportButton.addEventListener('click', () => { | |
if (reportButton.dataset.thumbnailVisibility == 'hidden') { | |
playAll(videos); | |
reportButton.dataset.thumbnailVisibility = 'visible'; | |
} else { | |
pauseAll(videos); | |
reportButton.dataset.thumbnailVisibility = 'hidden'; | |
} | |
}); | |
} | |
pauseReportVideo(); | |
document.addEventListener('visibilitychange', () => { | |
var videos = document.querySelectorAll('video:not(.videoReportThumb)'); | |
if (document.hidden) { | |
pauseAll(videos); | |
} else { | |
playAll(videos); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment