71 lines
2.1 KiB
JavaScript
71 lines
2.1 KiB
JavaScript
// ==UserScript==
|
|
// @name netflix-speed
|
|
// @version 0.9
|
|
// @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) {
|
|
var elem = node.querySelector('.button-nfplayerNextEpisode') || node.querySelector('.button-nfplayerEpisodes') || node.querySelector('.button-nfplayerSubtitles');
|
|
if (node.matches && node.matches('.AkiraPlayer') && elem) {
|
|
resolve(elem.parentNode);
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
});
|
|
}
|
|
|
|
function inject_controls() {
|
|
find_controls().then(function(controls) {
|
|
/* remove report a problem button */
|
|
if (document.querySelector('div.ReportAProblemPopupContainer'))
|
|
document.querySelector('div.ReportAProblemPopupContainer').remove();
|
|
|
|
/* don't inject multiple times */
|
|
if (document.querySelector('#speed-control'))
|
|
return;
|
|
|
|
/* create speed_control element */
|
|
var speed_control = document.createElement('div');
|
|
speed_control.innerHTML = `<select>
|
|
<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>
|
|
</select>`;
|
|
speed_control.id = 'speed-control';
|
|
speed_control.style.cssText = `
|
|
padding: 0 0 1.68em 0;
|
|
margin: 0 1.5em;`;
|
|
speed_control.firstChild.style.cssText = `
|
|
-webkit-appearance: none;
|
|
background: none;
|
|
border: none;
|
|
font-size: 2.2em;
|
|
text-align: right;`;
|
|
speed_control.firstChild.onchange = function() {
|
|
document.querySelector('.VideoContainer video').playbackRate = this.value;
|
|
};
|
|
|
|
/* inject speed_control element */
|
|
controls.before(speed_control);
|
|
|
|
/* redo injection, in case of video change, ... */
|
|
inject_controls();
|
|
});
|
|
};
|
|
|
|
/* initial run of injection */
|
|
inject_controls();
|