Skip to content

Commit

Permalink
Closes #948
Browse files Browse the repository at this point in the history
  • Loading branch information
ParticleCore committed Mar 1, 2024
1 parent 0abb930 commit e705969
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/chrome/js/background-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,40 @@ function mainScript(extensionId, SettingData, defaultSettings) {

};

const preventScrollTop = (() => {

let original = null;

const override = () => {

const watchFlexy = document.querySelector("ytd-watch-flexy");

if (watchFlexy) {
original = watchFlexy.setScrollTop;
watchFlexy.setScrollTop = () => {
};
}

};

const restore = () => {

const watchFlexy = document.querySelector("ytd-watch-flexy");

if (watchFlexy) {
watchFlexy.setScrollTop = original;
original = null;
}

};

return {
override: override,
restore: restore
}

})();

const updateState = event => {

moviePlayer ??= document.getElementById("movie_player");
Expand All @@ -939,13 +973,15 @@ function mainScript(extensionId, SettingData, defaultSettings) {
&& parentRects.bottom < parentRects.height * .5
) {
if (!isAlwaysVisible()) {
preventScrollTop.override();
document.documentElement.setAttribute("always-visible-player", "");
window.addEventListener("mousedown", onMouseDown, true);
window.addEventListener("contextmenu", onContextMenu, true);
updatePosition();
window.dispatchEvent(new CustomEvent("resize"));
}
} else if (isAlwaysVisible()) {
preventScrollTop.restore();
document.documentElement.removeAttribute("always-visible-player");
window.removeEventListener("mousedown", onMouseDown, true);
window.removeEventListener("contextmenu", onContextMenu, true);
Expand Down
36 changes: 36 additions & 0 deletions src/firefox/js/background-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,40 @@ function mainScript(extensionId, SettingData, defaultSettings) {

};

const preventScrollTop = (() => {

let original = null;

const override = () => {

const watchFlexy = document.querySelector("ytd-watch-flexy");

if (watchFlexy) {
original = watchFlexy.setScrollTop;
watchFlexy.setScrollTop = () => {
};
}

};

const restore = () => {

const watchFlexy = document.querySelector("ytd-watch-flexy");

if (watchFlexy) {
watchFlexy.setScrollTop = original;
original = null;
}

};

return {
override: override,
restore: restore
}

})();

const updateState = event => {

moviePlayer ??= document.getElementById("movie_player");
Expand All @@ -939,13 +973,15 @@ function mainScript(extensionId, SettingData, defaultSettings) {
&& parentRects.bottom < parentRects.height * .5
) {
if (!isAlwaysVisible()) {
preventScrollTop.override();
document.documentElement.setAttribute("always-visible-player", "");
window.addEventListener("mousedown", onMouseDown, true);
window.addEventListener("contextmenu", onContextMenu, true);
updatePosition();
window.dispatchEvent(new CustomEvent("resize"));
}
} else if (isAlwaysVisible()) {
preventScrollTop.restore();
document.documentElement.removeAttribute("always-visible-player");
window.removeEventListener("mousedown", onMouseDown, true);
window.removeEventListener("contextmenu", onContextMenu, true);
Expand Down

0 comments on commit e705969

Please sign in to comment.