Skip to content

Instantly share code, notes, and snippets.

@htkcodes
Created November 19, 2017 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htkcodes/78afeef9af9d071de178b5a852d1b423 to your computer and use it in GitHub Desktop.
Save htkcodes/78afeef9af9d071de178b5a852d1b423 to your computer and use it in GitHub Desktop.
FLOAT YT
function iniFloater() {
var player, plrApi, out_of_sight, isFloater, isFScreen, floaterUI, settings_open;
player = document.getElementById("movie_player");
plrApi = document.getElementById("player-api").getBoundingClientRect();
settings_open = document.getElementById("P-settings");
if (player) {
out_of_sight = plrApi.bottom < ((plrApi.height / 2) + 50);
isFloater = document.documentElement.classList.contains("floater");
isFScreen = document.querySelector(".ytp-fullscreen");
floaterUI = document.getElementById("part_floaterui");
if (!floaterUI && !isFScreen) {
floaterUI = document.createElement("template");
floaterUI.innerHTML = //
`<div id='part_floaterui'>
<button id='part_floaterui_move' data-p='ttl|VID_PLR_ALVIS_MOVE'><svg viewBox='0 0 20 20'><polygon points='6.4,3.6 7.2,4.3 10,1.5 12.8,4.3 13.6,3.6 10,0'/><polygon points='16.4,6.4 15.7,7.2 18.5,10 15.7,12.8 16.4,13.6 20,10'/><polygon points='3.6,6.4 0,10 3.6,13.6 4.3,12.8 1.5,10 4.3,7.2'/><polygon points='10,18.5 7.2,15.7 6.4,16.4 10,20 13.6,16.4 12.8,15.7'/><circle cx='10' cy='10' r='2'/></svg></button>
<button id='part_floaterui_scrolltop' data-p='ttl|VID_PLR_ALVIS_SCRL_TOP'><svg viewBox='0 0 20 20'><polygon points='10,0.1 0,10.1 2.9,12.9 10,5.8 17.1,12.9 20,10.1 '/></svg></button>
</div>`;
floaterUI = setLocale(floaterUI.content).firstChild;
player.appendChild(floaterUI);
document.getElementById("part_floaterui_move").addEventListener("mousedown", dragFloater);
document.getElementById("part_floaterui_scrolltop").addEventListener("click", goToTop);
}
if (out_of_sight && !isFloater && !settings_open && window.location.pathname === "/watch") {
document.documentElement.classList.add("floater");
window.addEventListener("resize", updatePos);
updatePos();
window.dispatchEvent(new Event("resize"));
} else if ((!out_of_sight || settings_open || window.location.pathname !== "/watch") && isFloater) {
document.documentElement.classList.remove("floater");
window.removeEventListener("resize", updatePos);
player.removeAttribute("style");
window.dispatchEvent(new Event("resize"));
}
}
}
function alwaysVisible() {
if (user_settings.VID_PLR_ALVIS) {
if (window.location.pathname === "/watch") {
window.addEventListener("scroll", iniFloater);
} else if (window.location.pathname !== "/watch") {
window.removeEventListener("scroll", iniFloater);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment