Skip to content

Instantly share code, notes, and snippets.

@thegitfather
Last active December 7, 2020 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thegitfather/25248169ab131e1bc578a3597d7aa668 to your computer and use it in GitHub Desktop.
Save thegitfather/25248169ab131e1bc578a3597d7aa668 to your computer and use it in GitHub Desktop.
Twitch Auto Fullscreen (tampermonkey)
// ==UserScript==
// @name Twitch Auto Fullscreen
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Enter fullscreen after a countdown (ESC to cancel)
// @author You
// @include https://www.twitch.tv/*
// @include https://twitch.tv/*
// @require https://cdnjs.cloudflare.com/ajax/libs/umbrella/3.1.0/umbrella.min.js
// @grant GM_addStyle
// @run-at document-idle
// ==/UserScript==
GM_addStyle(".fscounter { text-align: center; position: absolute; top: calc(50% - 5rem); width: 100%;}");
GM_addStyle(".fscounter span { font-size: 10rem; position: relative; padding: 0; margin: 0; line-height: 1em; }");
GM_addStyle(".fscounter span { text-shadow: 1px 1px 2px black, 0 0 25px white, 0 0 5px yellow; }");
(function() {
'use strict';
const html_fscounter = '<div class="fscounter"><span></span></div>'
let pathname = ''
new MutationObserver(() => {
const userRegExp = /^\/[a-zA-Z0-9\-_]+$/
const userUrlTrigger = location.pathname.match(userRegExp)
const isSearch = location.pathname.match(/^\/search/)
if (pathname !== location.pathname && userUrlTrigger && !isSearch) {
const fsbutton = u('.player-button.qa-fullscreen-button')
if (fsbutton.length) {
if (!u('.video-player.video-player--fullscreen').length) {
startFullscreenCounter(3, fsbutton)
}
pathname = location.pathname
}
}
}).observe(document.getElementsByTagName('title')[0] || document, { childList: true, subtree: true });
function startFullscreenCounter(countdown, btn) {
const videoEl = u('.video-player video')
const videoContainer = u(videoEl).parent()
if (videoContainer) {
let fscounter = u(videoContainer).append(() => html_fscounter)
const fsc_span = u(fscounter).find('span')
let counter = null
u(document).handle('keyup', (e) => {
if(counter && e.key === "Escape") {
clearInterval(counter)
}
})
counter = setInterval(() => {
u(fsc_span).html(countdown--)
if (u('.video-player.video-player--fullscreen').length) clear()
else if (countdown === -1) {
u(btn).trigger('click')
clear()
}
}, 1000)
if (counter) {
u(document).handle('keyup', escHandler)
u('.video-player').on('click', clear)
}
function escHandler(e) {
if (counter && e.key === "Escape") clear()
}
function clear() {
u(document).off('keyup', escHandler)
u('.video-player').off('click', clear)
if (counter) clearInterval(counter)
u(fscounter).find('.fscounter').remove()
}
}
}
})();
@asdsadsaasd12312132
Copy link

Does this still work? Nothing happens when I enter a stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment