Last active
March 27, 2021 18:31
-
-
Save danny8376/28ba980a059422695107c8cde8b2c236 to your computer and use it in GitHub Desktop.
Auto skip unplayable video for StreamElements MediaRequest
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 StreamElements MediaRequest Auto-Skip Error Video | |
// @namespace http://saru.moe/ | |
// @version 0.1 | |
// @description Auto skip unplayable video for StreamElements MediaRequest | |
// @author DannyAAM | |
// @match https://streamelements.com/widgets/mememachine* | |
// @match https://streamelements.com/dashboard/mediarequest/general | |
// @icon https://www.google.com/s2/favicons?domain=streamelements.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// ==== media request page part ==== | |
if (window.location.href.startsWith("https://streamelements.com/dashboard/mediarequest/general")) { | |
window.addEventListener("message", (event) => { | |
if (event.data === "saru.moe:StreamElements_MediaRequest_Auto-Skip_Error_Video:skipVideo") { | |
if (!document.querySelector(".se-notification-bar-visible")) { // check if current activated instance (avoid multiple skip) | |
window.document.querySelector(".songrequest-player-actions-icon-skip").dispatchEvent(new MouseEvent("click")); | |
} | |
} | |
}); | |
} | |
// ==== internal yt widget part ==== | |
if (window.location.href.startsWith("https://streamelements.com/widgets/mememachine")) { | |
function skipToNext() { | |
window.parent.postMessage("saru.moe:StreamElements_MediaRequest_Auto-Skip_Error_Video:skipVideo", "https://streamelements.com/"); | |
} | |
let notPlayingTimeout = null; | |
const oriOnYouTubeIframeAPIReadyForSaru = window.onYouTubeIframeAPIReady; | |
window.onYouTubeIframeAPIReady = function() { | |
oriOnYouTubeIframeAPIReadyForSaru(); // ori init | |
window.onYouTubeIframeAPIStateForSaru = function(event) { | |
if (event.data === -1) { // not playing | |
notPlayingTimeout = setTimeout(function() { | |
skipToNext(); | |
}, 5000); | |
} else { | |
clearTimeout(notPlayingTimeout); | |
} | |
}; | |
window.onYouTubeIframeAPIErrorForSaru = function(event) { | |
skipToNext(); | |
}; | |
window.player.addEventListener("onStateChange", "onYouTubeIframeAPIStateForSaru"); | |
window.player.addEventListener("onError", "onYouTubeIframeAPIErrorForSaru"); | |
}; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment