From 10c74e1082494b315deb6a430795d70b35ca67fa Mon Sep 17 00:00:00 2001 From: Jorg Are Date: Wed, 21 May 2025 13:45:10 +0100 Subject: [PATCH] feat: update captions content (#36732) --- webpack.common.config.js | 2 ++ webpack.dev.config.js | 4 +++- webpack.prod.config.js | 4 +++- xmodule/js/src/video/09_video_caption.js | 21 ++++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/webpack.common.config.js b/webpack.common.config.js index ca2ae36849..8deea2b4f6 100644 --- a/webpack.common.config.js +++ b/webpack.common.config.js @@ -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: { diff --git a/webpack.dev.config.js b/webpack.dev.config.js index 45550a7041..6fe7a0199a 100644 --- a/webpack.dev.config.js +++ b/webpack.dev.config.js @@ -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: { diff --git a/webpack.prod.config.js b/webpack.prod.config.js index c8da4ff193..4626700130 100644 --- a/webpack.prod.config.js +++ b/webpack.prod.config.js @@ -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 diff --git a/xmodule/js/src/video/09_video_caption.js b/xmodule/js/src/video/09_video_caption.js index 90138c3ccc..6d8ff00332 100644 --- a/xmodule/js/src/video/09_video_caption.js +++ b/xmodule/js/src/video/09_video_caption.js @@ -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);