Reload Twitch

Reloads a Twitch page to check if stream is live, time settings are UTC and set for the FACEIT London 2018 CS:GO Major start times.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Reload Twitch
// @version      0.46
// @description  Reloads a Twitch page to check if stream is live, time settings are UTC and set for the FACEIT London 2018 CS:GO Major start times.
// @author       LaminatedSteel
// @include      https://www.twitch.tv/*
// @run-at       document-idle
// @noframes
// @grant        window.reload
// @namespace https://greasyfork.org/users/141414
// ==/UserScript==

(function() {
    'use strict';

    setInterval(function() {
        reloadTwitch(9, 5);
        reloadTwitch(9, 6);
        reloadTwitch(9, 7);
        reloadTwitch(9, 8);
        reloadTwitch(9, 9);
        reloadTwitch(9, 12);
        reloadTwitch(9, 13);
        reloadTwitch(9, 14);
        reloadTwitch(9, 15);
        reloadTwitch(9, 16);
        reloadTwitch(14, 20);
        reloadTwitch(15, 21);
        reloadTwitch(15, 22);
        reloadTwitch(17, 23);
    }, 300000);
})();

function reloadTwitch(utcHours, utcDayOfMonth) {
    //If for some reason the player itself hasn't loaded, refresh the page
    if (!document.getElementsByClassName('video-player__container')[0]) {
        window.location.reload(true);
    }

    //If there is an error on the player, refresh the page
    //if (document.getElementsByClassName('video-player__container')[0].getAttribute('data-screen') == "error") {
    //    window.location.reload(true);
    //}

    var now = new Date();
    var isAfterStartTimeOnCorrectDay = (now.getUTCDate() == utcDayOfMonth && now.getUTCHours() >= utcHours);
    
    if (isAfterStartTimeOnCorrectDay && (document.getElementsByClassName('player-streamstatus__label').length == 0 || document.getElementsByClassName('player-streamstatus__label')[0].innerHTML != "Live" || document.getElementsByClassName('player-tip--aleft')[0].attributes[1].value == "Play")) {
        window.location.reload(true);
    }
}