Mute Yandex Music Ads (Fork)

Mute Yandex.Music advertising!

// ==UserScript==
// @name         Mute Yandex Music Ads (Fork)
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Mute Yandex.Music advertising!
// @author       You
// @match        https://music.yandex.ru/*
// @noframes
// @grant        none
// @license      MIT
// ==/UserScript==
'use strict';

var timerTry = 500;
var currentPlays = true;
var playing = false;

function toogleMute() {
    window.document.querySelector('.volume__btn').click();
}

window.document.querySelector('.player-controls__btn_seq').addEventListener("click", (event) => {
  playing = true;

  if (!window.document.querySelector('.player-controls__btn_play').classList.contains('player-controls__btn_pause')) {
    window.document.querySelector('.player-controls__btn_play').click();
  }
});

window.document.querySelector('.player-controls__btn_play').addEventListener("click", (event) => {
  playing = window.document.querySelector('.player-controls__btn_play').classList.contains('player-controls__btn_pause');
  console.log('playing', playing);
});



function setupObservers() {
  var songInfo = window.document.querySelector('title').innerText;

  if (songInfo !== null) {
    if (songInfo === 'Реклама') {
      if (currentPlays) {
        console.log("Mute Yandex Ads");
        toogleMute();
        currentPlays = false;
      }
    } else if (!currentPlays) {
      console.log("UnMute Yandex Ads");
      toogleMute();
      currentPlays = true;
    }
  }

  if (playing && !window.document.querySelector('.player-controls__btn_play').classList.contains('player-controls__btn_pause')) {
    window.document.querySelector('.player-controls__btn_play').click();
  }

  setTimeout(setupObservers, timerTry);
}

setTimeout(setupObservers, timerTry);