Skip to content

Instantly share code, notes, and snippets.

@SimPiko
Last active March 25, 2016 00:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimPiko/662af17ea3f0e64cc335 to your computer and use it in GitHub Desktop.
Save SimPiko/662af17ea3f0e64cc335 to your computer and use it in GitHub Desktop.
Twitch.tv - force old flash player (updated, should work on https)
// ==UserScript==
// @name Twitch.tv - force old flash player
// @namespace somethingsomethingtwitch
// @description Replaces default twitch player with old Flash player.
// @description original author - 420foxbot
// @description link to original script - https://gitlab.com/foxbot/Twitch5ForAll/raw/master/twitch5.user.js
// @version 1.1
// @grant none
// @match http://*.twitch.tv/*
// @match https://*.twitch.tv/*
// @exclude http://*.twitch.tv/*/v/*
// @exclude https://*.twitch.tv/*/v/*
// ==/UserScript==
/*
modified "Twitch Force new Player"
with help of - https://github.com/justintv/Twitch-API/blob/master/embedding.md
author of original script - 420foxbot
link to original script - https://gitlab.com/foxbot/Twitch5ForAll/raw/master/twitch5.user.js
*/
var hostTimeout = 0;
function waitForHost() {
hostTimeout += 1;
if (document.getElementById("hostmode")) {
console.log("Twitch5: Found host!");
hostTimeout = 100;
replaceHost();
setTimeout(removeButton, 5000);
return;
}
else if (hostTimeout > 20)
{
return;
}
else
{
setTimeout(waitForHost, 500);
}
}
function waitForPlayer() {
if (document.getElementById("player")) {
replacePlayer();
}
else
{
setTimeout(waitForPlayer, 500);
}
}
function replacePlayer() {
var full = window.location.href;
var chan = full.replace("https://www.twitch.tv/","");
var done = chan.replace("/popout","");
if (full.indexOf("popout") > -1)
{
console.log("Twitch5: Found channel: " + done);
//document.getElementsByClassName("player-container")[0].innerHTML = '<iframe src=\"http://player.twitch.tv/?channel=' + done + '\" height=\"100%\" width=\"100%\" frameborder=\"0\" allowfullscreen=\"true\" webkitallowfullscreen=\"true\" mozallowfullscreen=\"true\"></iframe>';
//http://www.twitch.tv/swflibs/TwitchPlayer.swf
//http://www-cdn.jtvnw.net/swflibs/TwitchPlayer.rfc07d37fc4eed1d17243b452dd3441665496e1e0.swf
document.getElementsByClassName("player-container")[0].innerHTML = '<object type=\"application/x-shockwave-flash\" height=\"100%\" width=\"100%\" data=\"https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.rfc07d37fc4eed1d17243b452dd3441665496e1e0.swf\" bgcolor="#000000"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowNetworking\" value=\"all\" /><param name=\"movie\" value=\"https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.rfc07d37fc4eed1d17243b452dd3441665496e1e0.swf\" /><param name=\"flashvars\" value="channel=' + done + '\&auto_play=true\&\" /></object>';
console.log("Twitch 5: Popout player replaced.");
}
else
{
console.log("Twitch5: Found channel: " + done);
document.getElementById("player").innerHTML = '<object type=\"application/x-shockwave-flash\" height=\"100%\" width=\"100%\" data=\"https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.rfc07d37fc4eed1d17243b452dd3441665496e1e0.swf\" bgcolor="#000000"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowNetworking\" value=\"all\" /><param name=\"movie\" value=\"https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.rfc07d37fc4eed1d17243b452dd3441665496e1e0.swf\" /><param name=\"flashvars\" value="channel=' + done + '\&auto_play=true\&\" /></object>';
console.log("Twitch5: Player replaced.");
}
return;
}
function replaceHost() {
var chan = getAllElementsWithAttribute('data-tt_content');
var full = 'http://www.twitch.tv/';
chan.forEach(function(entry){
if (entry.getAttribute('data-tt_content') == "host_channel") {
full = entry.getAttribute('href');
}
});
var done = full.replace("http://www.twitch.tv/","");
console.log("Twitch5: Found host channel: " + done);
document.getElementById("player").innerHTML = '<object type=\"application/x-shockwave-flash\" height=\"100%\" width=\"100%\" data=\"https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.rfc07d37fc4eed1d17243b452dd3441665496e1e0.swf\" bgcolor="#000000"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowNetworking\" value=\"all\" /><param name=\"movie\" value=\"https://www-cdn.jtvnw.net/swflibs/TwitchPlayer.rfc07d37fc4eed1d17243b452dd3441665496e1e0.swf\" /><param name=\"flashvars\" value="channel=' + done + '\&auto_play=true\&\" /></object>';
console.log("Twitch5: Host player replaced.");
return;
}
function removeButton() {
document.getElementById("video-playback").setAttribute("data-branding", "false");
document.getElementById("video-playback").setAttribute("data-showinfo", "false");
console.log("Button removed!");
}
// Thanks to StackOverflow user 'kevinfahy'
function getAllElementsWithAttribute(attribute)
{
var matchingElements = [];
var allElements = document.getElementsByTagName('*');
for (var i = 0, n = allElements.length; i < n; i++)
{
if (allElements[i].getAttribute(attribute) !== null)
{
// Element exists with attribute. Add to array.
matchingElements.push(allElements[i]);
}
}
return matchingElements;
}
waitForPlayer();
setTimeout(removeButton, 5000);
waitForHost();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment