Created
October 8, 2022 10:37
-
-
Save Yanrishatum/d27d85cde8f948f2a3fb529adf2f7b08 to your computer and use it in GitHub Desktop.
Youtube better volume slider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Expavol | |
// @namespace http://yanrishatum.ru/ | |
// @version 0.2 | |
// @description Exponential volume for youtube. Because fuck linear volume. Barbarians. | |
// @author Yanrishatum | |
// @match https://*.youtube.com/* | |
// @match https://youtube.com/* | |
// @match https://youtu.be/* | |
// @match https://music.youtube.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var validVolume = 0.5; | |
var obs = new MutationObserver(function(rec, obs) { | |
for (let r of rec) { | |
let linear = parseFloat(r.target.getAttribute(r.attributeName)) / 100; | |
let sqrt = Math.pow(linear, 2); | |
validVolume = sqrt; | |
setVol(); | |
} | |
}); | |
function setVol() { | |
var vid = document.querySelector("video") | |
vid.volume = validVolume; | |
requestAnimationFrame(function() { | |
vid.volume = validVolume; | |
}) | |
} | |
var hooked = []; | |
function lookup() { | |
var vol = document.querySelector(".ytp-volume-panel,.volume-slider tp-yt-paper-progress"); | |
if (hooked.indexOf(vol) == -1) { | |
hooked.push(vol); | |
obs.observe(vol, { | |
attributes: true, | |
attributeFilter: ["aria-valuenow"], | |
}); | |
} | |
} | |
lookup(); | |
// TODO: Expect page reload without actual page reload -> rehook volume | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment