|
// ==UserScript== |
|
// @name Custom Playback Rate and Volume (context-menu) |
|
// @namespace tampermonkey-scripts |
|
// @description Sets custom playback rate and volume for HTML5 videos |
|
// @version 1.0 |
|
// @match *://*/* |
|
// @grant none |
|
// @run-at context-menu |
|
// ==/UserScript== |
|
|
|
(function () { |
|
if (window._gainNode) { |
|
let video = document.querySelector("video"); |
|
if (video._mediaElementSourceNode) { |
|
setPlaybackRateAndVolume(); |
|
} else { |
|
setPlaybackRateAndVolumeWithSourceNode(video); |
|
} |
|
} else { |
|
let video = document.querySelector("video"); |
|
setAudioGain(video); |
|
} |
|
|
|
function setPlaybackRateAndVolume() { |
|
let playbackRate = parseFloat(prompt("Set the playback rate")); |
|
if (playbackRate >= 10) { |
|
if (confirm("The volume you have set is a little loud (" + playbackRate + "), are you sure you want to continue?")) { |
|
window._gainNode.gain.value = playbackRate; |
|
} else { |
|
setPlaybackRateAndVolume(); |
|
} |
|
} else { |
|
window._gainNode.gain.value = playbackRate; |
|
} |
|
} |
|
|
|
function setPlaybackRateAndVolumeWithSourceNode(video) { |
|
let audioContext = new AudioContext(); |
|
let sourceNode = audioContext.createMediaElementSource(video); |
|
let gainNode = audioContext.createGain(); |
|
|
|
function setPlaybackRateAndVolume() { |
|
let playbackRate = parseFloat(prompt("Set the playback rate")); |
|
if (playbackRate >= 10) { |
|
if (confirm("The volume you have set is a little loud (" + playbackRate + "), are you sure you want to continue?")) { |
|
window._gainNode = gainNode; |
|
gainNode.gain.value = playbackRate; |
|
sourceNode.connect(gainNode); |
|
gainNode.connect(audioContext.destination); |
|
video._mediaElementSourceNode = sourceNode; |
|
} else { |
|
setPlaybackRateAndVolume(); |
|
} |
|
} else { |
|
window._gainNode = gainNode; |
|
gainNode.gain.value = playbackRate; |
|
sourceNode.connect(gainNode); |
|
gainNode.connect(audioContext.destination); |
|
video._mediaElementSourceNode = sourceNode; |
|
} |
|
} |
|
|
|
setPlaybackRateAndVolume(); |
|
} |
|
|
|
function setAudioGain(video) { |
|
let audioContext = new AudioContext(); |
|
let sourceNode = audioContext.createMediaElementSource(video); |
|
let gainNode = audioContext.createGain(); |
|
|
|
function setGain() { |
|
let audioGain = parseFloat(prompt("Set the audio gain")); |
|
if (audioGain >= 10) { |
|
if (confirm("The volume you have set is a little loud (" + audioGain + "), are you sure you want to continue?")) { |
|
gainNode.gain.value = audioGain; |
|
sourceNode.connect(gainNode); |
|
gainNode.connect(audioContext.destination); |
|
window._gainNode = gainNode; |
|
video._mediaElementSourceNode = sourceNode; |
|
} else { |
|
setGain(); |
|
} |
|
} else { |
|
gainNode.gain.value = audioGain; |
|
sourceNode.connect(gainNode); |
|
gainNode.connect(audioContext.destination); |
|
window._gainNode = gainNode; |
|
video._mediaElementSourceNode = sourceNode; |
|
} |
|
} |
|
|
|
setGain(); |
|
} |
|
})(); |