// ==UserScript==
// @name NetflixVideoSpeedControl
// @version 1.0
// @description Add speed control to Netflix
// @author kevduc
// @namespace https://kevduc.github.io/
// @homepageURL https://github.com/kevduc/userscripts
// @downloadURL https://raw.githubusercontent.com/kevduc/userscripts/master/NetflixVideoSpeedControl.user.js
// @updateURL https://raw.githubusercontent.com/kevduc/userscripts/master/NetflixVideoSpeedControl.user.js
// @supportURL https://github.com/kevduc/userscripts/issues
// @include https://www.netflix.com/watch/*
// @grant none
// @run-at document-end
// @icon https://www.google.com/s2/favicons?sz=128&domain=netflix.com
// ==/UserScript==
;(function () {
'use strict'
addSpeedControl()
function addSpeedControl() {
// Get the video
const video = document.querySelector('video')
// Get a toolbar button (e.g. "Report a problem")
const reportAProblemDiv = document.querySelector('.ReportAProblemPopupContainer')
// Check if the video and the button are on the page yet
if (video === null || reportAProblemDiv === null) {
// If not, wait a bit before retrying
window.setTimeout(addSpeedControl, 500)
return
}
// Clone the toolbar button
const videoSpeedDiv = reportAProblemDiv.insertAdjacentElement('afterend', reportAProblemDiv.cloneNode(true))
// Fix: Prevent propagation of mouseup event (because the document mouseup event handler is annoying and closes the dropdown)
videoSpeedDiv.addEventListener('mouseup', (event) => event.stopPropagation())
// Change the description and icon of the buttton
const button = videoSpeedDiv.querySelector('button')
button.ariaLabel = 'Control the video speed'
button.innerHTML = ``
// Change the popup content
const contentWrapperDiv = videoSpeedDiv.querySelector('.popup-content-wrapper')
contentWrapperDiv.innerHTML = `