globalSpeed icon indicating copy to clipboard operation
globalSpeed copied to clipboard

Question(s) about addon

Open Fireworkstars46 opened this issue 4 years ago • 10 comments

How exactly do I set up a volume up and volume down shortcut key making it go every single percent (1 2 3, etc up to 100)?

Fireworkstars46 avatar Apr 25 '22 17:04 Fireworkstars46

Hello. Create two "volume" shortcuts in the options page. Set the first one to -0.01 for 1% volume down. Set the other for 0.01 for 1% volume up. Newly created shortcuts aren't bound to any keys so click on "NoKey" and press your preferred shortcut key for both.

https://user-images.githubusercontent.com/31208859/165189189-0bcc185d-ad2f-4e1f-a5f6-604cd6340b44.mov

polywock avatar Apr 25 '22 23:04 polywock

Ok. Also is it possible to set the volume to a default percentage? Like every tab or a specific website I got to, have it be at a specific percentage.

Fireworkstars46 avatar Apr 26 '22 02:04 Fireworkstars46

Sadly not. By the way, speaking of default volume. Some websites like Youtube only store volume changes if it's made through the video's volume slider.

Scanario 1: If you change volume to 80% using Youtube's own volume slider. If you refresh the page, volume should still be 80%.

Scanario 2: If you change volume to 80% using a Global Speed shortcut. If you refresh the page, volume will not be 80%.


This is is kind of annoying, you can use this script to fix that (for Youtube). To setup...

  1. Create a URL rule in the options page.
  2. Change it from "speed" mode to "javascript" mode. Click "edit" and paste the code from below.
  3. Click on "-- 0 --" to add a URL condition so that if the URL contains "youtube.com", it should run the code.
  4. Enable "ILO" so the code only loads once.
if (!window.ranScriptFlag) {
    window.ranScriptFlag = true

    // add event listener to persist volume on volume change 
    window.addEventListener("volumechange", e => {
        const video = e.target
        if (!(video instanceof HTMLMediaElement)) return 

        const now = new Date().getTime() 
        const data = JSON.stringify({volume: Math.round(video.volume * 100), muted: video.muted})
        const payload = JSON.stringify({data, expiration: now + 2592000000, creation: now})
        localStorage.setItem("yt-player-volume", payload)
        sessionStorage.setItem("yt-player-volume", payload)
    }, true)
}

https://user-images.githubusercontent.com/31208859/165215878-b9e3b363-7886-4f4d-a1e8-659478cc3338.mov

polywock avatar Apr 26 '22 03:04 polywock

How would I do it with non YouTube sites? Like Disney now etc?

Fireworkstars46 avatar May 02 '22 22:05 Fireworkstars46

This should work on all sites. This script blocks the website from changing volume at all. The limitation is that you can only change volume using Global Speed, and it will remember the volume even if you refresh the page. I recommend only running it on sites that you notice issues like Youtube. To setup for Disney+ and Youtube, just change the URL condition and replace the javascript to this.

sc5

[ REMOVED ]

polywock avatar May 05 '22 19:05 polywock

What about making it so when I set the volume to like 25 on Disney now and have it save there if the page refreshes or something?

Fireworkstars46 avatar Jun 15 '22 23:06 Fireworkstars46

Hello. Here's an updated version. You can now change your volume through Youtube or Disney's own controls as long as it's after 5 seconds of the video loading. It should save when you refresh the page.

[ REMOVED ]

polywock avatar Jun 16 '22 04:06 polywock

@Fireworkstars46 I just noticed a big issue with a code. It should be setTimeout instead of setInterval. This could result in issues. Here's a fixed version.

if (!window.ranScriptFlag) {
    window.ranScriptFlag = true
    let blockTimeout 
    // block website from changing volume for first 3 seconds. 
    let BLOCK_DURATION = 3000 

    // add event listener to store latest volume. 
    window.addEventListener("volumechange", e => {
        const video = e.target
        if (!(video instanceof HTMLMediaElement)) return 

        localStorage.setItem("gs-volume", video.volume)
    }, true)


    // function to get stored volume 
    const getStoredVolume = () => {
        let volumeRaw = localStorage.getItem("gs-volume")
        if (volumeRaw) {
            return parseFloat(volumeRaw)
        }
    }

    // block page from changing volume 
    const desc = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume")
    Object.defineProperty(HTMLMediaElement.prototype, "volume", {configurable: true, enumerable: true, get: desc.get, set: function(value) {
     return blockTimeout ? undefined : desc.set.call(this, value) 
}})

    // on start of video, set volume to the stored one. 
    window.addEventListener("loadedmetadata", e => {
        const video = e.target
        if (!(video instanceof HTMLMediaElement)) return 
        clearTimeout(blockTimeout)
        blockTimeout = setTimeout(() => { blockTimeout = null }, BLOCK_DURATION)
        desc.set.call(video, getStoredVolume() ?? 0.5)
    }, true)
}

polywock avatar Jun 17 '22 12:06 polywock

Are you plan on adding a discord server for this addon?

Fireworkstars46 avatar Oct 10 '23 23:10 Fireworkstars46

Hello. I probably should, but Discord kills my productivity.

polywock avatar Oct 11 '23 12:10 polywock