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

Commit

Permalink
What until Youtube video has loaded data to request a video quality c…
Browse files Browse the repository at this point in the history
…hange. (#1659)
  • Loading branch information
MortimerGoro authored and bluemarvin committed Aug 27, 2019
1 parent 9be94c1 commit 23a68b6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/src/main/assets/web_extensions/webcompat_youtube/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ try {
viewportEl.parentNode.removeChild(viewportEl);
}

onNavigate(0);
// 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
var video = document.getElementsByTagName("video")[0];
if (video.readyState >= 2) {
onNavigate(0);
} else {
video.addEventListener("loadeddata", () => onNavigate(0));
}
});

window.addEventListener('pushstate', onNavigate);
Expand Down Expand Up @@ -275,7 +283,7 @@ try {
log(`Changed quality from "${currentQuality}" to "${newBestQuality}"`);
};

window.onYouTubePlayerReady = evt => {
window.wrappedJSObject.onYouTubePlayerReady = evt => {
log('`onYouTubePlayerReady` called');
window.ytImprover(1);
evt.addEventListener('onStateChange', 'ytImprover');
Expand All @@ -284,9 +292,9 @@ try {

window.addEventListener('spfready', () => {
log('`spfready` event fired');
if (typeof window.ytplayer === 'object' && window.ytplayer.config) {
if (window.wrappedJSObject.ytplayer && window.wrappedJSObject.ytplayer.config) {
log('`window.ytplayer.config.args.jsapicallback` set');
window.ytplayer.config.args.jsapicallback = 'onYouTubePlayerReady';
window.wrappedJSObject.ytplayer.config.args.jsapicallback = 'onYouTubePlayerReady';
}
});

Expand Down

0 comments on commit 23a68b6

Please sign in to comment.