Skip to content

Instantly share code, notes, and snippets.

@jasonrahm
Last active January 31, 2021 18:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonrahm/b8e580f080467e2b781d7340a56a065f to your computer and use it in GitHub Desktop.
Save jasonrahm/b8e580f080467e2b781d7340a56a065f to your computer and use it in GitHub Desktop.
Streamyard Keyboard Shortcuts
// ==UserScript==
// @name Streamyard_Hotkeys
// @version 0.13
// @description Enable hotkeys for keyboard shortcuts
// @author Jason Rahm
// @match https://streamyard.com/*
// @grant none
// ==/UserScript==
(async function() {
'use strict';
document.addEventListener("keydown", event => {
switch(event.keyCode) {
case 49:
// keystroke: 1 (for banner #1)
clickAsset("#broadcast-aside-content-banners > div > div.BannerList__Wrap-jdqcZv.jDhECk > ul > li:nth-child(1) > div > button")
break;
case 50:
// keystroke: 2 (for banner #2)
clickAsset("#broadcast-aside-content-banners > div > div.BannerList__Wrap-jdqcZv.jDhECk > ul > li:nth-child(2) > div > button")
break;
case 66:
// keystroke: b (for background)
clickAsset("img[alt='dc_connects']")
break;
case 72:
// keystroke: h (for hide)
// Hide "Mic is muted" message
hideAsset("#app > div > div > main > div > div.Studio__VideoRow-gequmb.kWcqDI > div > div > div.CenterAlerts__Column-hqLAGq.gWSwES")
break;
case 73:
// keystroke: i (for intro)
// Toggle Intro Overlay
clickAsset("img[alt='dccintro_final']")
break;
case 76:
// keystroke: l (for logo)
// Toggle 150x150 Logo
clickAsset("img[alt='f5profilelogo']")
break;
case 80:
// keystroke: p (for promo)
// Toggle CCUA promo
clickAsset("img[alt='ccua_promo1']")
break;
default:
//do nothing
}
});
})();
/**
* Set Overlay
*
* @param {string} selector - Which asset selector to click
**/
async function clickAsset(selector){
await waitFor(selector);
let e = document.querySelector(selector);
e.click();
}
/**
* Hide Elements without clicking
**/
async function hideAsset(selector){
await waitFor(selector);
let e = document.querySelector(selector);
e.style.display = 'none';
}
/**
* waitFor
*
* @param {string} selector - Which selector to wait for
* @param {number} maxAttemps - How many attempts to try before giving up
* @param {number} intervalTime - How many milliseconds between the attempts
**/
function waitFor(selector, maxAttempts=20, intervalTime=200){
let tries = 0
return new Promise((resolve, reject) => {
let t = setInterval(() => {
if(document.querySelectorAll(selector).length > 0 || tries >= maxAttempts){
clearInterval(t);
resolve();
}
}, 100);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment