Skip to content

Instantly share code, notes, and snippets.

@bwasty
Created November 18, 2021 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwasty/b841ef42f27e90d9c19567dd6081c59d to your computer and use it in GitHub Desktop.
Save bwasty/b841ef42f27e90d9c19567dd6081c59d to your computer and use it in GitHub Desktop.
lipyantar-language-reactor-netflix
// bookmarklet-title: lipyantar-language-reactor-netflix
// bookmarklet-about: Transliterates Devanagari subtitles to ISO/IAST when using Language Reactor
let current_subtitle_element = null;
function transliterate_current_subtitle(timestamp) {
window.transliterationAnimFrameID = window.requestAnimationFrame(transliterate_current_subtitle);
let el = document.getElementById('lln-subs');
if (!el || el == current_subtitle_element)
return;
let translit_div = document.createElement('div');
translit_div.style = "font-size: 0.9em; color: lightgreen";
translit_div.className = 'lln-whole-title-translation';
let text = el.innerText;
let translit = Sanscript.t(text, 'devanagari', 'iso', {syncope: true});
translit_div.innerText = translit;
el.insertAdjacentElement('afterend', translit_div);
current_subtitle_element = el;
}
function setupTransliteration() {
window.cancelAnimationFrame(window.transliterationAnimFrameID);
transliterate_current_subtitle();
}
if (!window.Sanscript) {
let script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/@sanskrit-coders/sanscript@1.2.0/sanscript.min.js';
script.type = 'text/javascript';
script.async = true;
script.onload = function(){
setupTransliteration();
};
document.body.appendChild(script);
}
else {
setupTransliteration();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment