diff --git a/out/PiPer-chrome.zip b/out/PiPer-chrome.zip
index 47ded06..8b62e0a 100644
Binary files a/out/PiPer-chrome.zip and b/out/PiPer-chrome.zip differ
diff --git a/out/PiPer-safari-legacy.safariextz b/out/PiPer-safari-legacy.safariextz
index 593a9a8..718b8a1 100644
Binary files a/out/PiPer-safari-legacy.safariextz and b/out/PiPer-safari-legacy.safariextz differ
diff --git a/out/PiPer-safari.pkg b/out/PiPer-safari.pkg
index e89291a..cde6109 100644
Binary files a/out/PiPer-safari.pkg and b/out/PiPer-safari.pkg differ
diff --git a/src/common/scripts/captions.js b/src/common/scripts/captions.js
index b02cc99..115b3d0 100644
--- a/src/common/scripts/captions.js
+++ b/src/common/scripts/captions.js
@@ -41,7 +41,7 @@ export const enableCaptions = function(ignoreNowPlayingCheck) {
const video = /** @type {?HTMLVideoElement} */ (getResource().videoElement(true));
if (!video) return;
showingCaptions = videoPlayingPictureInPicture(video);
- prepareCaptions(video);
+ track = getCaptionTrack(video);
processCaptions();
};
@@ -55,27 +55,35 @@ export const shouldProcessCaptions = function() {
};
/**
- * Prepares video for captions
+ * Gets caption track for video (creates or returns existing track as needed)
*
* @param {HTMLVideoElement} video - video element that will display captions
+ * @return {TextTrack}
*/
-const prepareCaptions = function(video) {
+const getCaptionTrack = function(video) {
// Find existing caption track
- track = null;
const allTracks = video.textTracks;
for (let trackId = allTracks.length; trackId--;) {
if (allTracks[trackId].label === TRACK_ID) {
- track = allTracks[trackId];
info('Existing caption track found');
- break;
+ return allTracks[trackId];
}
}
- if (track) return;
// Otherwise create new caption track
info('Caption track created');
- track = video.addTextTrack('captions', TRACK_ID, 'en');
+ return video.addTextTrack('captions', TRACK_ID, 'en');
+};
+
+/**
+ * Adds caption tracks to all video elements
+ */
+export const addVideoCaptionTracks = function() {
+ const elements = document.getElementsByTagName('video');
+ for (let index = 0, element; element = elements[index]; index++) {
+ getCaptionTrack(/** @type {?HTMLVideoElement} */ (element));
+ }
};
/**
@@ -88,7 +96,7 @@ const pictureInPictureEventListener = function(video, isPlayingPictureInPicture)
// Toggle display of the captions and prepare video if needed
showingCaptions = isPlayingPictureInPicture;
- if (showingCaptions) prepareCaptions(video);
+ if (showingCaptions) track = getCaptionTrack(video);
lastUnprocessedCaption = '';
processCaptions();
diff --git a/src/common/scripts/main.js b/src/common/scripts/main.js
index f6e7261..ddfaec4 100644
--- a/src/common/scripts/main.js
+++ b/src/common/scripts/main.js
@@ -3,7 +3,7 @@ import { Browser, getBrowser, getResource, setResource } from './common.js'
import { addVideoElementListeners } from './video.js'
import { resources } from './resources/index.js';
import { checkButton, addButton } from './button.js'
-import { shouldProcessCaptions, enableCaptions, processCaptions } from './captions.js'
+import { shouldProcessCaptions, enableCaptions, processCaptions, addVideoCaptionTracks } from './captions.js'
import { initialiseCaches } from './cache.js'
/**
@@ -17,6 +17,9 @@ const mutationObserver = function() {
// Workaround Chrome's lack of an entering Picture in Picture mode event by monitoring all video elements
if (getBrowser() == Browser.CHROME) addVideoElementListeners();
+ // Workaround Safari bug; captions are not displayed if the track is added after the video has loaded
+ if (getBrowser() == Browser.SAFARI) addVideoCaptionTracks();
+
// Try adding the button to the page if needed
if (checkButton()) return;
const currentResource = getResource();
diff --git a/src/safari-legacy/update.plist b/src/safari-legacy/update.plist
index f335e63..4a38f03 100644
--- a/src/safari-legacy/update.plist
+++ b/src/safari-legacy/update.plist
@@ -10,7 +10,7 @@
CFBundleShortVersionString
1.0.3
CFBundleVersion
- 213
+ 214
Developer Identifier
BQ6Q24MF9X
URL