feat: update captions content (#36732)

This commit is contained in:
Jorg Are
2025-05-21 13:45:10 +01:00
committed by GitHub
parent 30ace04469
commit 10c74e1082
4 changed files with 28 additions and 3 deletions

View File

@@ -67,6 +67,8 @@ var workerConfig = function() {
}),
new webpack.DefinePlugin({
'process.env.JS_ENV_EXTRA_CONFIG': JSON.parse(process.env.JS_ENV_EXTRA_CONFIG),
'CAPTIONS_CONTENT_TO_REPLACE': JSON.stringify(process.env.CAPTIONS_CONTENT_TO_REPLACE || ''),
'CAPTIONS_CONTENT_REPLACEMENT': JSON.stringify(process.env.CAPTIONS_CONTENT_REPLACEMENT || '')
})
],
module: {

View File

@@ -21,7 +21,9 @@ module.exports = _.values(Merge.smart(commonConfig, {
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
'process.env.JS_ENV_EXTRA_CONFIG': process.env.JS_ENV_EXTRA_CONFIG || '{}'
'process.env.JS_ENV_EXTRA_CONFIG': process.env.JS_ENV_EXTRA_CONFIG || '{}',
'CAPTIONS_CONTENT_TO_REPLACE': JSON.stringify(process.env.CAPTIONS_CONTENT_TO_REPLACE || ''),
'CAPTIONS_CONTENT_REPLACEMENT': JSON.stringify(process.env.CAPTIONS_CONTENT_REPLACEMENT || '')
})
],
module: {

View File

@@ -19,7 +19,9 @@ var optimizedConfig = Merge.smart(commonConfig, {
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
'process.env.JS_ENV_EXTRA_CONFIG': process.env.JS_ENV_EXTRA_CONFIG || '{}'
'process.env.JS_ENV_EXTRA_CONFIG': process.env.JS_ENV_EXTRA_CONFIG || '{}',
'CAPTIONS_CONTENT_TO_REPLACE': JSON.stringify(process.env.CAPTIONS_CONTENT_TO_REPLACE || ''),
'CAPTIONS_CONTENT_REPLACEMENT': JSON.stringify(process.env.CAPTIONS_CONTENT_REPLACEMENT || '')
}),
new webpack.LoaderOptionsPlugin({ // This may not be needed; legacy option for loaders written for webpack 1
minimize: true

View File

@@ -38,7 +38,7 @@
'showClosedCaptions', 'hideClosedCaptions', 'toggleClosedCaptions',
'updateCaptioningCookie', 'handleCaptioningCookie', 'handleTranscriptToggle',
'listenForDragDrop', 'setTranscriptVisibility', 'updateTranscriptCookie',
'updateGoogleDisclaimer', 'toggleGoogleDisclaimer'
'updateGoogleDisclaimer', 'toggleGoogleDisclaimer', 'updateProblematicCaptionsContent'
);
this.state = state;
@@ -540,6 +540,21 @@
}
},
/**
* @desc Replaces content in a caption
*
* @param {array} captions List of captions for the video.
* @param {string} content content to be replaced
* @param {string} replacementContent the replace string
*
* @returns {array} captions List of captions for the video.
*/
updateProblematicCaptionsContent: function(captions, content = '', replacementContent = '') {
var updatedCaptions = captions.map(caption => caption.replace(content, replacementContent));
return updatedCaptions;
},
/**
* @desc Fetch the caption file specified by the user. Upon successful
* receipt of the file, the captions will be rendered.
@@ -594,6 +609,10 @@
results = self.getBoundedCaptions();
start = results.start;
captions = results.captions;
var contentToReplace = CAPTIONS_CONTENT_TO_REPLACE,
replacementContent = CAPTIONS_CONTENT_REPLACEMENT;
captions = self.updateProblematicCaptionsContent(captions, contentToReplace, replacementContent);
self.renderGoogleDisclaimer(captions);