← All examples

JavaScript Media youtube.com

YouTube: remember the volume level

Saves the volume you set and restores it on every new video and after a page reload.

Code to copy

// Remember the player volume across videos and page loads
const KEY = 'jz-yt-volume';
function apply(v) {
  if (!v) return;
  v.volume = parseFloat(localStorage.getItem(KEY) || v.volume);
  v.addEventListener('volumechange', () => {
    localStorage.setItem(KEY, String(v.volume));
  });
}
const obs = new MutationObserver(() => {
  const v = document.querySelector('video.html5-main-video');
  if (v && !v.dataset.jzVol) { v.dataset.jzVol = '1'; apply(v); }
});
obs.observe(document.documentElement, { childList: true, subtree: true });

How to use this example

  1. Copy the code with the button above.
  2. Install JustZix (2 minutes) and open the extension on the target page.
  3. Add a new rule matching that page.
  4. Paste the code into the rule's JavaScript panel and save — it runs on every page visit.

Rate this example

No ratings yet — be the first.

Does this example work?

Snippets are useless without somewhere to paste them.

JustZix takes 2 minutes to install and runs your code on every matching page. No account, no payment.

Download free See use cases