StreamProtocol for Twitch and HitBox

Watch Twitch and HitBox in an external player

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        StreamProtocol for Twitch and HitBox
// @namespace   sp-twitch
// @description Watch Twitch and HitBox in an external player
// @include http://www.twitch.tv/*
// @include https://www.twitch.tv/*
// @include http://www.hitbox.tv/*
// @include https://www.hitbox.tv/*
// @version     1
// @grant       none
// ==/UserScript==
// Based on original version by https://greasyfork.org/en/users/3167-winceptor

console.log("grabbing");

var host = window.location.host;
	
var hook = function()
{
	if (host=="www.twitch.tv")
	{
		var div = document.querySelectorAll('.channel-actions')[0];
		if (div==null) {
			setTimeout(function(){hook();},1000);
			return
		}

		var user = document.URL.split("twitch.tv/")[1].split("/")[0];

		var tokenurl = 'http://api.twitch.tv/api/channels/' + user + '/access_token?grabber';
        $.get(tokenurl, function(data) {
            var token = data['token'];
            var signature = data['sig'];

            var url = 'http://usher.justin.tv/api/channel/hls/' + user + '.m3u8?allow_source=true&token=' + token + '&sig=' + signature;
            var urle = encodeURI(url);
            
            var newspan = document.createElement("span");
            newspan.innerHTML = '<span class="ember-view button action"><a href="stream+' + urle + '">View in external player</a></span>';
            div.appendChild(newspan);
        });
		console.log("Hooking...");
	}

	if (host=="www.hitbox.tv")
	{
		var div = document.querySelectorAll('.stats')[0];
		if (div==null) {
			setTimeout(function(){hook();},1000);
			return
		}

		var user = document.URL.split("hitbox.tv/")[1].split("/")[0];

		var url = 'http://api.hitbox.tv/player/hls/' + user + '.m3u8';

		var newspan = document.createElement("span");
		newspan.innerHTML = '<a href="stream+' + url + '">View in external player</a>';
		div.appendChild(newspan);    

		console.log("Hooking...");
	}
}

hook();

console.log("StreamProtocol for Twitch and HitBox: " + host);