Skip to content

Commit

Permalink
Merge pull request #22 from amarcu5/develop-hotfix
Browse files Browse the repository at this point in the history
v0.2.2+hotfix.1
  • Loading branch information
amarcu5 authored Aug 30, 2017
2 parents 2c29f28 + 53d35d8 commit 6188d0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Binary file modified out/PiPer.safariextz
Binary file not shown.
27 changes: 13 additions & 14 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ const prepareCaptions = function(video) {
/**
* Removes visible Picture in Picture mode captions
* @param {HTMLVideoElement} video - video element showing captions
* @param {boolean} workaround - apply Safari bug workaround
*/
const removeCaptions = function(video) {
const removeCaptions = function(video, workaround = true) {
track.mode = 'showing';
while (track.activeCues.length) track.removeCue(track.activeCues[0]);

// Workaround Safari bug; 'removeCue' doesn't immediately remove captions shown in Picture in Picture mode
track.addCue(new VTTCue(video.currentTime, video.currentTime, ''));
if (workaround) track.addCue(new VTTCue(video.currentTime, video.currentTime + 60, ''));
}

/**
Expand All @@ -145,11 +146,9 @@ const processCaptions = function() {
const captionElement = currentResource.captionElement();
const video = /** @type {?HTMLVideoElement} */ (currentResource.videoElement());

// Remove old captions
removeCaptions(video);

// Show native captions if no longer showing captions or encountered an error
// Remove Picture in Picture mode captions and show native captions if no longer showing captions or encountered an error
if (!showingCaptions || !captionElement) {
removeCaptions(video);
if (captionElement) captionElement.style.visibility = '';
return;
}
Expand All @@ -162,6 +161,9 @@ const processCaptions = function() {
if (unprocessedCaption == lastUnprocessedCaption) return;
lastUnprocessedCaption = unprocessedCaption;

// Remove old captions and apply Safari bug fix if caption has no content as otherwise causes flicker
removeCaptions(video, !unprocessedCaption);

// Performance optimisation - early exit if caption has no content
if (!unprocessedCaption) return;

Expand Down Expand Up @@ -653,29 +655,26 @@ const resources = {

// Workaround Safari bug; old captions persist in Picture in Picture mode when MediaSource buffers change
const video = /** @type {?HTMLVideoElement} */ (currentResource.videoElement());
document.addEventListener('spfrequest', function(){
window.addEventListener('yt-navigate-start', function() {
showingCaptions = false;
removeCaptions(video);
});
document.addEventListener('spfdone', function(){
window.addEventListener('yt-navigate-finish', function() {
showingCaptions = video.webkitPresentationMode == 'picture-in-picture';
});
},
buttonInsertBefore: function(/** Element */ parent) {
return parent.lastChild;
},
buttonParent: function() {
const e = document.getElementById('movie_player') || document.getElementById('player');
return e && e.querySelector('.ytp-right-controls');
return document.querySelector('.ytp-right-controls');
},
buttonScale: 0.68,
captionElement: function() {
const e = document.getElementById('movie_player') || document.getElementById('player');
return e && e.querySelector('.captions-text');
return document.querySelector('.caption-window');
},
videoElement: function() {
const e = document.getElementById('movie_player') || document.getElementById('player');
return e && e.querySelector('video.html5-main-video');
return document.querySelector('video.html5-main-video');
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion update.plist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<key>CFBundleShortVersionString</key>
<string>0.2.2</string>
<key>CFBundleVersion</key>
<string>63</string>
<string>73</string>
<key>Developer Identifier</key>
<string>BQ6Q24MF9X</string>
<key>URL</key>
Expand Down

0 comments on commit 6188d0e

Please sign in to comment.