-
Notifications
You must be signed in to change notification settings - Fork 6
/
BrainFmBeta.bsstrategy
93 lines (84 loc) · 2.27 KB
/
BrainFmBeta.bsstrategy
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// BrainFmBetaStrategy.m
// BeardedSpice
//
// Created by Andy Chong on 6 Apr 2022.
// Copyright (c) 2022 Andy Chong. All rights reserved.
//
BSStrategy = {
version: 1,
displayName: "Brain.fm beta",
accepts: {
method: "predicateOnTab",
format: "%K LIKE[c] '*my.brain.fm/*'",
args: ["URL"],
},
isPlaying: function () {
const element = document.querySelector(
"[src^='/static/media/pause_icon']",
);
return element !== null;
},
toggle: function () {
const pause = document.querySelector(
"[src^='/static/media/pause_icon']",
);
const play = document.querySelector(
"[src^='/static/media/play_icon']",
);
if(!!pause) {
pause.closest('button').click();
}else if(!!play) {
play.closest('button').click();
}
},
previous: function () {},
next: function () {
const element = document.querySelector(
"[src^='/static/media/skip_icon']",
);
element && element.closest('button').click();
},
pause: function () {
const isPlaying = document.querySelector(
"[src^='/static/media/pause_icon']",
) !== null;
const element = document.querySelector(
"[src^='/static/media/pause_icon']",
);
isPlaying && element && element.click()
},
favorite: function () {
const element = document.querySelector(
"[data-testid='addToFavoritesButton']",
);
element && element.click()
},
trackInfo: function () {
const art = document.querySelector(
"[src^='https://images.unsplash.com/']",
);
let album, track;
if(art && art.nextSibling && art.nextSibling.children[0]) {
track = art.nextSibling.children[0].innerText;
if(art.nextSibling.children[0].nextSibling) {
album = art.nextSibling.children[0].nextSibling.innerText;
}
}
let favorited = false;
const favoriteBtn = document.querySelector(
"[data-testid='addToFavoritesButton']",
);
if (favoriteBtn && favoriteBtn.firstElementChild) {
favorited =
favoriteBtn.firstElementChild.getAttribute("fill-opacity") === "1";
}
return {
image: art ? art.getAttribute("src") : "",
track: track ? track : "",
album: album ? album : "",
artist: "",
favorited: favorited,
};
},
};