Example of *.vtt file (subtitles)
WEBVTT line have to be there.
WEBVTT
1
00:00:01.000 –> 00:00:02.000
First line
2
00:00:03.000 –> 00:00:04.000
Second line
Add javascript:
// Auto-add VTT subtitles for Breakdance videos (works even in new tab)
(function() {
'use strict';
const CONFIG = {
videoSelectors: [
'video',
'.bde-video video',
'.breakdance-video video',
'.ee-video video'
]
};
let processedVideos = new Set();
function initAutoSubtitles() {
const videos = findAllVideos();
// Fallback: ak stránka obsahuje len jedno video priamo
if (videos.length === 0 && document.querySelector('video')) {
videos.push(document.querySelector('video'));
}
videos.forEach((video, index) => {
const videoId = video.src || video.currentSrc || video.outerHTML.substring(0, 100);
if (!processedVideos.has(videoId)) {
processedVideos.add(videoId);
addVttSubtitle(video, index + 1);
}
});
}
function findAllVideos() {
const videos = [];
CONFIG.videoSelectors.forEach(selector => {
document.querySelectorAll(selector).forEach(video => {
if (!videos.includes(video)) videos.push(video);
});
});
return videos;
}
function addVttSubtitle(video, videoNumber, attempt = 0) {
const src = video.src || video.currentSrc;
if (!src) {
// Retry if src isn't ready yet
if (attempt < 5) {
setTimeout(() => addVttSubtitle(video, videoNumber, attempt + 1), 500);
}
return;
}
// Extract folder path and file name
const urlParts = src.split('/');
const fileName = urlParts.pop().split('.')[0]; // remove extension
const folderPath = urlParts.join('/') + '/';
const subtitleUrl = folderPath + fileName + '.vtt';
// Check if track already exists
if (video.querySelector('track[kind="subtitles"]')) return;
const track = document.createElement('track');
track.kind = 'subtitles';
track.src = subtitleUrl;
track.srclang = 'en';
track.label = 'English';
track.default = true;
video.appendChild(track);
video.load();
video.addEventListener('loadedmetadata', () => {
if (video.textTracks && video.textTracks.length > 0) {
video.textTracks[0].mode = 'showing';
console.log(`✅ Video ${videoNumber}: Subtitles enabled`);
}
});
}
// Observe dynamically added videos
const observer = new MutationObserver(mutations => {
let newVideo = false;
mutations.forEach(m => {
m.addedNodes.forEach(node => {
if (node.nodeType === 1 && (node.tagName === 'VIDEO' || node.querySelector('video'))) {
newVideo = true;
}
});
});
if (newVideo) setTimeout(initAutoSubtitles, 500);
});
observer.observe(document.body, { childList: true, subtree: true });
// Run on page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initAutoSubtitles);
} else {
initAutoSubtitles();
}
// Fallback: ensure subtitles load even after full window load
window.addEventListener('load', () => setTimeout(initAutoSubtitles, 1000));
console.log('🚀 Breakdance auto-VTT subtitles loaded (works in new tab too)');
})();
