Created
February 29, 2016 16:10
-
-
Save andreasvirkus/7038496d1c88f21741ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Twitch.tv - force old flash player | |
// @namespace ajvtwitchold | |
// @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 | |
// @grant none | |
// @match http://*.twitch.tv/* | |
// ==/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("http://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>'; | |
document.getElementsByClassName("player-container")[0].innerHTML = '<object type=\"application/x-shockwave-flash\" height=\"100%\" width=\"100%\" data=\"//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf\" bgcolor="#000000"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowNetworking\" value=\"all\" /><param name=\"movie\" value=\"//www-cdn.jtvnw.net/swflibs/TwitchPlayer.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=\"//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf\" bgcolor="#000000"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowNetworking\" value=\"all\" /><param name=\"movie\" value=\"//www-cdn.jtvnw.net/swflibs/TwitchPlayer.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=\"//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf\" bgcolor="#000000"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowNetworking\" value=\"all\" /><param name=\"movie\" value=\"//www-cdn.jtvnw.net/swflibs/TwitchPlayer.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