forked from beardedspice/BS-Strategies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrainFm.bsstrategy
101 lines (93 loc) · 2.55 KB
/
BrainFm.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
94
95
96
97
98
99
100
101
//
// BrainFmStrategy.m
// BeardedSpice
//
// Created by James Greenleaf on 03/05/16.
// Copyright (c) 2013 Tyler Rhodes / Jose Falcon. All rights reserved.
//
// Updated by:
// - V2: Andy Chong on 19 Oct 2020.
// - V3: Andy Chong on 26 Nov 2021.
//
BSStrategy = {
version: 3,
displayName: "Brain.fm",
accepts: {
method: "predicateOnTab",
format: "%K LIKE[c] '*brain.fm/*'",
args: ["URL"],
},
isPlaying: function () {
const element = document.querySelector(
"[class^='playerControl__ControlButtons']",
);
if (
element &&
element.firstElementChild &&
element.firstElementChild.firstElementChild
) {
return !element.firstElementChild.firstElementChild.alt.match(/play/i);
}
},
toggle: function () {
const element = document.querySelector(
"[class^='playerControl__ControlButtons']",
);
if (element && element.firstElementChild) {
element.firstElementChild.click();
}
},
previous: function () {},
next: function () {
const element = document.querySelector(
"[class^='playerControl__ControlButtons']",
);
if (element && element.lastElementChild) {
element.lastElementChild.click();
}
},
pause: function () {
const element = document.querySelector(
"[class^='playerControl__ControlButtons']",
);
if (element && element.firstElementChild) {
element.firstElementChild.click();
}
},
favorite: function () {
const element = document.querySelector("[class*='AddToFavoritesButton']");
if (element) {
element.click();
}
},
trackInfo: function () {
const art = document.querySelector(
"[class^='TrackInformationCardstyles__Image']",
);
const title = document.querySelector(
"[class^='TrackInformationCardstyles__Title']",
);
const track = document.querySelector(
"[class^='TrackInformationCardstyles__Subtitle']",
);
const activity = document.querySelector(
"[class^='ActivitySelectorstyles__Text']",
);
let favorited = false;
const favoriteBtn = document.querySelector(
"[class*='AddToFavoritesButton']",
);
if (favoriteBtn && favoriteBtn.firstElementChild) {
favorited =
favoriteBtn.firstElementChild.getAttribute("fill-opacity") === "1";
}
const info = {
image: art ? art.getAttribute("src") : null,
track: track ? track.innerText : null,
album: title ? title.innerText : null,
artist: activity ? activity.innerText : null,
favorited: favorited,
};
return info;
},
};