Twitch PiP button

Add picutre in picture button to twitch.tv player. Only for macOS 10.12+

当前为 2016-11-03 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Twitch PiP button
// @namespace   https://github.com/valera5505
// @description Add picutre in picture button to twitch.tv player. Only for macOS 10.12+
// @author      Valery Kirichenko
// @homepage    https://github.com/valera5505/twitch-pip-button
// @match      http://www.twitch.tv/*
// @match      http://player.twitch.tv/*
// @version     1.0
// @grant       none
// ==/UserScript==

var playerReady = setInterval(function() {
	if (document.querySelector("div.player-buttons-right")) {
		clearInterval(playerReady);
		var css = document.createElement("link");
		css.rel = "stylesheet";
		css.href = "https://cdn.rawgit.com/valera5505/twitch-pip-button/master/style.css";
		document.getElementsByTagName("head")[0].appendChild(css);

		var btn = document.createElement("button");
		btn.className = "player-button";
		btn.type = "button";
		btn.style = "display: inline-block";
		btn.id = "pip-button";
		btn.innerHTML = '<span class="icon-1"></span>';
		btn.style.padding = "1px 5px 1em";

		document.querySelector("div.player-buttons-right").insertBefore(btn, document.querySelector("button.player-button--fullscreen"));
		btn.addEventListener("click", function() {
			document.querySelector("video").webkitSetPresentationMode('picture-in-picture');
		});
	}
}, 100);