Skip to content

Instantly share code, notes, and snippets.

@Yanrishatum
Created June 2, 2020 21:27
Show Gist options
  • Save Yanrishatum/70584c25564b47e18953ade9ebc6d2e6 to your computer and use it in GitHub Desktop.
Save Yanrishatum/70584c25564b47e18953ade9ebc6d2e6 to your computer and use it in GitHub Desktop.
Exponential volume slider for youtube
// ==UserScript==
// @name Expavol
// @namespace http://yanrishatum.ru/
// @version 0.1
// @description Exponential volume for youtube. Because fuck linear volume. Barbarians.
// @author Yanrishatum
// @match https://*.youtube.com/*
// @match https://youtube.com/*
// @match https://youtu.be/*
// @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");
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