Adjust Instant-Buttons Sound Volume | MyInstants

Adjust Instant-Buttons Sound Volume

当前为 2023-05-03 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          	Adjust Instant-Buttons Sound Volume | MyInstants
// @name:de			    Anpassung der Instant-Button Lautstärke | MyInstants
// @namespace    	  https://greasyfork.org/users/928242
// @version        	1.0
// @description   	Adjust Instant-Buttons Sound Volume
// @description:de	Anpassung der Instant-Button Lautstärke
// @author       	  Kamikaze (https://github.com/Kamiikaze)
// @supportURL      https://github.com/Kamiikaze/Tampermonkey/issues
// @icon            https://www.google.com/s2/favicons?sz=64&domain=myinstants.com
// @match           https://www.myinstants.com/de/*
// @grant        	  none
// @license        	MIT
// ==/UserScript==



/* global audio */

const savedVolume = window.localStorage.getItem("soundVol")

setTimeout( () => {

    const instantsContainer = document.querySelector("#instants_container");

    const volumeLabel = document.createElement("label");
    volumeLabel.textContent = "Volume:";

    const volumeRange = document.createElement("input");
    volumeRange.type = "range";
    volumeRange.id = "volume-range";
    volumeRange.min = "0";
    volumeRange.max = "100";
    volumeRange.step = "0.1";
    volumeRange.value = savedVolume || "50";

    audio.volume = savedVolume / 100 || volumeRange.value / 100;



    const volumeNumber = document.createElement("input");
    volumeNumber.type = "number";
    volumeNumber.id = "volume-number";
    volumeNumber.min = "0";
    volumeNumber.max = "100";
    volumeNumber.step = "0.5";
    volumeNumber.value = savedVolume || "50";



    const volumeControlContainer = document.createElement("div");
    volumeControlContainer.id = "volume-control-container"
    volumeControlContainer.classList.add("sticky")
    volumeControlContainer.appendChild(volumeLabel);
    volumeControlContainer.appendChild(volumeRange);
    volumeControlContainer.appendChild(volumeNumber);

    instantsContainer.before(volumeControlContainer);



    volumeRange.addEventListener("input", () => {
        changeVolume(volumeRange.value);
    });

    volumeNumber.addEventListener("input", () => {
        changeVolume(volumeNumber.value);
    });

    function changeVolume(vol) {
        const newVolume = vol / 100
        audio.volume = newVolume;
        volumeNumber.value = vol;
        volumeRange.value = vol;
        window.localStorage.setItem("soundVol", parseFloat(vol).toFixed(1))
    }


    const style = document.createElement("style");
    style.textContent = `

  #volume-control-container {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 15px;
    background-color: rgb(0 0 0 / 50%);
    width: fit-content;
    padding: 10px 20px;
    margin: auto;
    border-radius: 10px;
  }

  #volume-control-container.sticky {
      position: fixed;
      top: 90px;
      right: 20px;
      z-index: 100;
      background-color: rgba(0, 0, 0, 0.8);
  }

  #volume-control-container input:nth-child(3) {
    max-width: 65px;
  }

`;

    document.head.appendChild(style);


}, 1000)