-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotmute.js
More file actions
49 lines (42 loc) · 1.28 KB
/
Copy pathspotmute.js
File metadata and controls
49 lines (42 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// ==UserScript==
// @name Spotify Ad Muter
// @version 4
// @description Mutes ads on Spotify
// @author redbeam
// @match https://open.spotify.com/*
// @grant none
// ==/UserScript==
"use strict";
var adtexts = [
"Spotify · Spotify",
"Advertisement · Spotify",
"Advertisement ·",
"Spotify – Reklama",
"Reklama"
];
var mutebutXpath = "/html/body/div[4]/div/div[2]/div[2]/footer/div/div[3]/div/div[3]/button";
var pageTitle = document.getElementsByTagName("title")[0];
var isMuted = false; // assuming the audio is not initially muted
function setMute(muteButton, state) {
if (state) {
if (!isMuted) {
muteButton.click();
isMuted = true;
}
} else {
if (isMuted) {
muteButton.click();
isMuted = false;
}
}
}
var pageTitleObserver = new MutationObserver(function() {
let mutebut = document.evaluate(mutebutXpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (adtexts.some(adtext => pageTitle.innerHTML.includes(adtext))) {
setMute(mutebut, true);
} else {
setMute(mutebut, false);
}
});
pageTitleObserver.observe(pageTitle, {childList: true});
console.log("Started Spotify Ad Muter");