Files
netflix-speed/netflix-speed.user.js
Alexander Weidinger 6fd55d841d Add css styling
2018-10-06 20:47:53 +02:00

57 lines
1.5 KiB
JavaScript

// ==UserScript==
// @name netflix-speed
// @version 0.1
// @include https://www.netflix.com/*
// ==/UserScript==
function find_controls() {
return new Promise(function(resolve, reject) {
var observer = new MutationObserver(function(mutationsList) {
mutationsList.forEach(function(mutation) {
var nodes = Array.from(mutation.addedNodes);
for (var node of nodes) {
if (node.parentNode && node.parentNode.matches && node.parentNode.matches('.PlayerControlsNeo__controls-group')) {
observer.disconnect();
resolve(node.parentNode);
return;
}
}
});
});
observer.observe(document.documentElement, { childList: true, subtree: true });
});
}
function inject_controls() {
find_controls().then(function(controls) {
var speed_control = document.createElement('select');
speed_control.style.cssText = `
border: none;
cursor: pointer;
background: none;
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
font-size: 1.96em;
padding-bottom: 0.84em;
`;
speed_control.onchange = function() {
document.querySelector('.VideoContainer video').playbackRate = this.value;
};
speed_control.innerHTML = `<option value=0.5>0.5</option>
<option value=0.75>0.75</option>
<option value=1.0 selected="selected">Normal</option>
<option value=1.25>1.25</option>
<option value=1.5>1.5</option>
<option value=1.75>1.75</option>
<option value=2.0>2.0</option>`;
controls.appendChild(speed_control);
inject_controls();
});
};
inject_controls();