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

Commit

Permalink
Fix Youtube queue context menu issues
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed May 18, 2020
1 parent 9d848c4 commit 827f57a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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
26 changes: 25 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,8 @@ 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'
};
const ENABLE_LOGS = true;
const logDebug = (...args) => ENABLE_LOGS && console.log(LOGTAG, ...args);
Expand Down Expand Up @@ -142,6 +143,27 @@ class YoutubeExtension {
}
}

fixQueueContextMenu() {
const handles = document.querySelectorAll(YT_SELECTORS.queueHandle);
for (var i=0; i<handles.length; i++) {
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;
}

// Runs the callback when the video is ready (has loaded the first frame).
waitForVideoReady(callback) {
this.retry("VideoReady", () => {
Expand Down Expand Up @@ -235,6 +257,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 +269,4 @@ 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.fixQueueContextMenu());

0 comments on commit 827f57a

Please sign in to comment.