Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FreshPenguin112
GitHub Repository: FreshPenguin112/bookmarklets
Path: blob/main/ytscroller.js
5051 views
1
function videoAnchor() {
2
var miniplayer = document.getElementsByClassName("miniplayer")[0];
3
if (miniplayer.parentElement.active) {
4
return;
5
}
6
var player = document.getElementById("movie_player");
7
var video = document.getElementsByTagName("video")[0];
8
var control = document.getElementsByClassName("ytp-chrome-bottom")[0];
9
var mastRect = document.getElementById("masthead-container").getBoundingClientRect();
10
var theaterRect = document.querySelector("#player-container.ytd-watch-flexy").getBoundingClientRect();
11
player.removeAttribute("style"); /* reset for theaterRect height */
12
var playerRect = player.getBoundingClientRect();
13
var videoRect = video.getBoundingClientRect();
14
if (theaterRect.bottom < mastRect.height) {
15
var comment = (
16
document.getElementById("primary-inner") ||
17
document.getElementById("primary")
18
);
19
var commentRect = comment.getBoundingClientRect();
20
var widthRatio = (window.innerWidth - commentRect.right) / videoRect.width;
21
var heightRatio = window.innerHeight / videoRect.height;
22
player.style.position = "fixed";
23
player.style.right = 0;
24
player.style.top = mastRect.height + "px";
25
player.style.width = videoRect.width + "px";
26
player.style.height = videoRect.height + "px";
27
player.style.transformOrigin = "right top";
28
player.style.transform = "scale(" + Math.min(widthRatio, heightRatio) + ")";
29
player.style.zIndex = 1500;
30
control.style.left = "12px";
31
control.style.width = (videoRect.width - 24) + "px";
32
video.style.left = 0;
33
}
34
else {
35
control.style.left = "12px";
36
control.style.width = (playerRect.width - 24) + "px";
37
video.style.left = (playerRect.width - videoRect.width) / 2 + "px";
38
}
39
}
40
function scrollAnchor() {
41
var x = window.scrollX;
42
var y = window.scrollY;
43
var t0;
44
function scrollToXY(t1) {
45
window.scrollTo(x, y);
46
if (typeof t0 == "undefined") {
47
t0 = t1;
48
}
49
if (t1 - t0 < 1) {
50
requestAnimationFrame(scrollToXY);
51
}
52
}
53
requestAnimationFrame(scrollToXY);
54
}
55
window.addEventListener("scroll", videoAnchor);
56
window.addEventListener("resize", videoAnchor);
57
window.addEventListener("mouseup", scrollAnchor);
58
59