Skip to content

Instantly share code, notes, and snippets.

@dannvix
Created February 4, 2018 09:06
Show Gist options
  • Save dannvix/38eff3e34b3f5259766950a8331f9df9 to your computer and use it in GitHub Desktop.
Save dannvix/38eff3e34b3f5259766950a8331f9df9 to your computer and use it in GitHub Desktop.
Make the SVG-based subtitles smaller on Netflix web player
// Only applied for "image-based timed text" (i.e. SVG-based, like Chinese, Japanese, ...)
// For DFXP-based subtitles (e.g., English), try the hidden settings: https://www.netflix.com/SubtitlePreferences
(() => {
const installScaler = () => {
const subRectElem = document.querySelector('rect.image-based-subtitles-rect');
if (subRectElem) {
const subWrapperElem = subRectElem.parentNode;
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
const config = {attributes: true, childList: true, characterData: true, };
const subChangeObserver = new MutationObserver((mutations) => {
[].forEach.call(subWrapperElem.querySelectorAll('image'), (subImgElem) => {
if (subImgElem && !subImgElem.classList.contains('scaled')) {
subImgElem.classList.add('scaled');
subImgElem.style.display = 'none';
//// Edit this ////
const scaleRatio = 0.5;
///////////////////
const origWidth = subImgElem.getAttribute('width');
const origHeight = subImgElem.getAttribute('height');
const newWidth = Math.floor(origWidth * scaleRatio);
const newHeight = Math.floor(origHeight * scaleRatio);
const origX = Math.floor(subImgElem.getAttribute('x'));
const origY = Math.floor(subImgElem.getAttribute('y'));
const newX = Math.floor(origX + 0.5 * (origWidth - newWidth));
const newY = Math.floor(origY + 0.5 * (origHeight - newHeight));
subImgElem.setAttribute('width', newWidth);
subImgElem.setAttribute('height', newHeight);
subImgElem.setAttribute('x', newX);
subImgElem.setAttribute('y', newY);
subImgElem.style.display = '';
}
});
});
subChangeObserver.observe(subWrapperElem, config);
return true;
}
return false;
}
if (window.location.href.toLowerCase().indexOf('netflix.com/watch') != -1) {
const interval = setInterval(() => {
if (installScaler()) {
console.log("Subtitle scaler installed!");
clearInterval(interval);
}
}, 1000);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment