Twitch Prevent Autoplay

Prevents Autoplay in embedded Twitch Players

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Twitch Prevent Autoplay
// @icon         https://www.twitch.tv/favicon.ico
// @namespace    https://github.com/TheTimmaeh/Twitch-Prevent-Autoplay
// @version      0.2
// @description  Prevents Autoplay in embedded Twitch Players
// @author       TheTimmaeh
// @match        *://player.twitch.tv/*
// @grant        none
// @supportURL   https://github.com/TheTimmaeh/Twitch-Prevent-Autoplay
// ==/UserScript==

// Initialize GET Object
var get = {};

// Read GET Parameters
var parameters = document.location.search.substr(1, document.location.search.length).split('&');

// Fill GET Object with GET Parameters
for(var i = 0; i <= parameters.length; i++) if(typeof parameters[i] === 'string' && parameters[i].length > 1) get[parameters[i].split('=')[0]] = parameters[i].split('=')[1] || null;

// Check for Video Source
if(typeof get.channel !== 'undefined' || typeof get.video !== 'undefined' || typeof get.collection !== 'undefined'){

  // Check for Autoplay Parameter
  if(typeof get.autoplay === 'undefined' || get.autoplay == 'true'){

    // Set Autoplay
    get.autoplay = false;

    // Build new iFrame URL
    var newurl = window.location.href.replace(window.location.search, '') + '?';

    // Add Parameters to iFrame URL
    for(var parameter in get) newurl += parameter + '=' + get[parameter] + '&';

    // Redirect to new iFrame URL
    document.location.href = newurl;
  }
}