Skip to content

Instantly share code, notes, and snippets.

@vasilake-v
Last active March 2, 2023 13:38
Show Gist options
  • Save vasilake-v/c0d761c92e86b4148281549bd13f33e7 to your computer and use it in GitHub Desktop.
Save vasilake-v/c0d761c92e86b4148281549bd13f33e7 to your computer and use it in GitHub Desktop.
*Tampermonkey script running on spotify app tab* It mutes the player when the "Advertisment" kicks-in, and once Ads are over it un-mutes the player back
// ==UserScript==
// @name Spotify-Mute-on-Ads
// @namespace http://tampermonkey.net/
// @version 0.1
// @description It mutes the player when the "Advertisment" kicks-in, and once Ads are over it un-mutes the player back
// @author Vasilake.sven
// @match https://open.spotify.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=spotify.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
let currentlyAdsAreOn = false;
function checkForAd() {
let adsEnabled = document.querySelector('footer[data-testid="now-playing-bar"][data-testadtype="ad-type-ad"]');
if (adsEnabled && currentlyAdsAreOn === false) {
currentlyAdsAreOn = true;
console.log('Advertisment enabled :( ');
toggleMute();
}
if (!adsEnabled && currentlyAdsAreOn === true) {
currentlyAdsAreOn = false;
console.log('Advertisment disabled :) ');
toggleMute();
}
setTimeout(checkForAd, 500);
}
function toggleMute() {
console.log('toggle mute');
document.querySelector('button[data-testid="volume-bar-toggle-mute-button"]').click();
}
// Your code here...
console.log('Start watching for advertisment...');
checkForAd();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment