Add Volume Control Slider

6/10/2024

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Add Volume Control Slider
// @namespace   Violentmonkey Scripts
// @match       https://www.redgifs.com/watch/*
// @grant       none
// @version     1.0
// @author      LovingObserver
// @license     GNU GPLv3
// @icon        https://icons.duckduckgo.com/ip2/redgifs.com.ico
// @description 6/10/2024
// ==/UserScript==

//create a MutationObserver instance to detect the video, since they are added dynamically
let observer = new MutationObserver((mutations, observer) => {
  //look through all mutations that just occured
  for(let mutation of mutations) {
    //if the addedNodes property has one or more nodes
    if(mutation.addedNodes.length) {
      let element = document.querySelector('.GifPreview_isActive');
      if(element) {
        //get the video element
        let video = document.querySelector('video');

        //set the video volume to the value stored in localStorage
        if (localStorage.getItem("videoVolume")) {
          video.volume = localStorage.getItem("videoVolume");
        } else {
          video.volume = 0.75;
        }

        //create a volume control slider
        let volumeControl = document.createElement('input');
        volumeControl.type = 'range';
        volumeControl.min = 0;
        volumeControl.max = 1;
        volumeControl.step = 0.01;
        volumeControl.value = video.volume;
        volumeControl.style.position = "absolute";
        volumeControl.style.top = "6px";
        volumeControl.style.right = "7.5px";
        volumeControl.style.zIndex = 3;
        volumeControl.style.cursor = "pointer";

        //update the video volume when the slider value changes
        volumeControl.addEventListener('input', (event) => {
          video.volume = volumeControl.value;
          localStorage.setItem("videoVolume", volumeControl.value);
        });

        //add the volume control to the page
        element.appendChild(volumeControl);

        //after the video element is found, stop observing
        observer.disconnect();
        return;
      }
    }
  }
});

//start observing the document with the configured parameters
observer.observe(document, { childList: true, subtree: true });