Skip to content

Commit 6188d0e

Browse files
authored
Merge pull request #22 from amarcu5/develop-hotfix
v0.2.2+hotfix.1
2 parents 2c29f28 + 53d35d8 commit 6188d0e

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

out/PiPer.safariextz

-316 Bytes
Binary file not shown.

src/scripts/main.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,14 @@ const prepareCaptions = function(video) {
127127
/**
128128
* Removes visible Picture in Picture mode captions
129129
* @param {HTMLVideoElement} video - video element showing captions
130+
* @param {boolean} workaround - apply Safari bug workaround
130131
*/
131-
const removeCaptions = function(video) {
132+
const removeCaptions = function(video, workaround = true) {
132133
track.mode = 'showing';
133134
while (track.activeCues.length) track.removeCue(track.activeCues[0]);
134135

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

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

148-
// Remove old captions
149-
removeCaptions(video);
150-
151-
// Show native captions if no longer showing captions or encountered an error
149+
// Remove Picture in Picture mode captions and show native captions if no longer showing captions or encountered an error
152150
if (!showingCaptions || !captionElement) {
151+
removeCaptions(video);
153152
if (captionElement) captionElement.style.visibility = '';
154153
return;
155154
}
@@ -162,6 +161,9 @@ const processCaptions = function() {
162161
if (unprocessedCaption == lastUnprocessedCaption) return;
163162
lastUnprocessedCaption = unprocessedCaption;
164163

164+
// Remove old captions and apply Safari bug fix if caption has no content as otherwise causes flicker
165+
removeCaptions(video, !unprocessedCaption);
166+
165167
// Performance optimisation - early exit if caption has no content
166168
if (!unprocessedCaption) return;
167169

@@ -653,29 +655,26 @@ const resources = {
653655

654656
// Workaround Safari bug; old captions persist in Picture in Picture mode when MediaSource buffers change
655657
const video = /** @type {?HTMLVideoElement} */ (currentResource.videoElement());
656-
document.addEventListener('spfrequest', function(){
658+
window.addEventListener('yt-navigate-start', function() {
657659
showingCaptions = false;
658660
removeCaptions(video);
659661
});
660-
document.addEventListener('spfdone', function(){
662+
window.addEventListener('yt-navigate-finish', function() {
661663
showingCaptions = video.webkitPresentationMode == 'picture-in-picture';
662664
});
663665
},
664666
buttonInsertBefore: function(/** Element */ parent) {
665667
return parent.lastChild;
666668
},
667669
buttonParent: function() {
668-
const e = document.getElementById('movie_player') || document.getElementById('player');
669-
return e && e.querySelector('.ytp-right-controls');
670+
return document.querySelector('.ytp-right-controls');
670671
},
671672
buttonScale: 0.68,
672673
captionElement: function() {
673-
const e = document.getElementById('movie_player') || document.getElementById('player');
674-
return e && e.querySelector('.captions-text');
674+
return document.querySelector('.caption-window');
675675
},
676676
videoElement: function() {
677-
const e = document.getElementById('movie_player') || document.getElementById('player');
678-
return e && e.querySelector('video.html5-main-video');
677+
return document.querySelector('video.html5-main-video');
679678
},
680679
},
681680
};

update.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<key>CFBundleShortVersionString</key>
1111
<string>0.2.2</string>
1212
<key>CFBundleVersion</key>
13-
<string>63</string>
13+
<string>73</string>
1414
<key>Developer Identifier</key>
1515
<string>BQ6Q24MF9X</string>
1616
<key>URL</key>

0 commit comments

Comments
 (0)