Guest User

backgroundMute

a guest
Sep 11th, 2020
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Mute sounds if window lost focus
  2. const soundOptions = ['audio', 'music', 'lizhi', 'yuyin', 'teshuyuyin'];
  3. var soundSettings = {};
  4. var waitaudiomod = setInterval(function() {
  5.     if (view && view.AudioMgr) {
  6.         unMute = function() {
  7.             if (old = window.localStorage.getItem('soundSettings'))
  8.                 soundSettings = JSON.parse(old);
  9.             Object.entries(soundSettings).forEach(([k, v]) => {
  10.                 view.AudioMgr[k] = v;
  11.             });
  12.         }
  13.         unMute();
  14.         document.body.onfocus = () => {
  15.             unMute();
  16.         }
  17.         document.body.onblur = () => {
  18.             soundOptions.forEach((n) => {
  19.                 soundSettings[n + 'Volume'] = view.AudioMgr[n + 'Volume'];
  20.                 soundSettings[n + 'Muted'] = view.AudioMgr[n + 'Muted'];
  21.                 window.localStorage.setItem('soundSettings',JSON.stringify(soundSettings));
  22.             });
  23.             soundOptions.forEach((n) => {
  24.                 view.AudioMgr[n + 'Muted'] = true;
  25.             });
  26.         }
  27.         clearInterval(waitaudiomod);
  28.     }
  29. }, 1000);
RAW Paste Data