Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Fixes #2611 Fixes # 2947 Youtube player fixes #3388

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ public void handleHoverEvent(MotionEvent aEvent) {

} else {
GeckoSession session = mSession.getGeckoSession();
if (session != null) {
if (session != null && !isContextMenuVisible()) {
session.getPanZoomController().onMotionEvent(aEvent);
}
}
Expand Down Expand Up @@ -1594,6 +1594,11 @@ public void reject() {
}
}

private boolean isContextMenuVisible() {
return (mContextMenu != null && mContextMenu.isVisible() ||
mSelectionMenu != null && mSelectionMenu.isVisible());
}

// GeckoSession.ContentDelegate

@Override
Expand Down
57 changes: 56 additions & 1 deletion app/src/main/assets/web_extensions/webcompat_youtube/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const YT_SELECTORS = {
embedPlayer: '.html5-video-player',
largePlayButton: '.ytp-large-play-button',
thumbnail: '.ytp-cued-thumbnail-overlay-image',
embedTitle: '.ytp-title-text'
embedTitle: '.ytp-title-text',
queueHandle: 'ytd-playlist-panel-video-renderer',
playbackControls: '.ytp-left-controls'
};
const ENABLE_LOGS = true;
const logDebug = (...args) => ENABLE_LOGS && console.log(LOGTAG, ...args);
Expand Down Expand Up @@ -142,6 +144,56 @@ class YoutubeExtension {
}
}

// Fix for the draggable items to continue being draggable when a context menu is displayed.
// https://github.com/MozillaReality/FirefoxReality/issues/2611
fixQueueContextMenu() {
const handles = document.querySelectorAll(YT_SELECTORS.queueHandle);
for (var i=0; i<handles.length; i++) {
handles[i].removeEventListener('contextmenu', this.onContextMenu);
handles[i].addEventListener('contextmenu', this.onContextMenu);
}
}

onContextMenu(event) {
setTimeout(() => {
var evt = document.createEvent("MouseEvents");
evt.initEvent("mouseup", true, true);
event.target.dispatchEvent(evt);
});

// This is supposed to prevent the context menu from showing but it doesn't seem to work
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
return false;
}

// Prevent the double click to reach the player to avoid double clicking
// to trigger a playback forward event.
// https://github.com/MozillaReality/FirefoxReality/issues/2947
videoControlsForwardFix() {
const playbackControls = document.querySelector(YT_SELECTORS.playbackControls);
playbackControls.removeEventListener("touchstart", this.videoControlsOnTouchStart);
playbackControls.addEventListener("touchstart", this.videoControlsOnTouchStart);
playbackControls.removeEventListener("touchend", this.videoControlsOnTouchEnd);
playbackControls.addEventListener("touchend", this.videoControlsOnTouchEnd);
}

videoControlsOnTouchStart(evt) {
evt.stopPropagation();
return false;
}

videoControlsOnTouchEnd(evt) {
evt.stopPropagation();
return false;
}

playerFixes() {
this.fixQueueContextMenu();
this.videoControlsForwardFix();
}

// Runs the callback when the video is ready (has loaded the first frame).
waitForVideoReady(callback) {
this.retry("VideoReady", () => {
Expand Down Expand Up @@ -235,6 +287,7 @@ youtube.overrideViewport();
window.addEventListener('load', () => {
logDebug('page load');
youtube.overrideVideoProjection();
youtube.fixQueueContextMenu();
// Wait until video has loaded the first frame to force quality change.
// This prevents the infinite spinner problem.
// See https://github.com/MozillaReality/FirefoxReality/issues/1433
Expand All @@ -246,3 +299,5 @@ window.addEventListener('load', () => {
window.addEventListener('pushstate', () => youtube.overrideVideoProjection());
window.addEventListener('popstate', () => youtube.overrideVideoProjection());
window.addEventListener('click', event => youtube.overrideClick(event));
window.addEventListener('mouseup', event => youtube.playerFixes());
window.addEventListener("yt-navigate-start", () => youtube.playerFixes());