forked from beardedspice/BS-Strategies
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicForProgramming.bsstrategy
More file actions
63 lines (63 loc) · 1.89 KB
/
Copy pathMusicForProgramming.bsstrategy
File metadata and controls
63 lines (63 loc) · 1.89 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// MusicForProgramming.plist
// BeardedSpice
//
// Created by Max Borghino on 12/01/15.
// Copyright (c) 2015 Tyler Rhodes / Jose Falcon. All rights reserved.
//
// strategy/site notes
// - single sets are long, so next/prev implements the site's forward/rewind on the set
// - track info consists only of the set number and name, no artist or artwork
// - if tab is newly loaded, toggle will not start playback. Playback must have been started already to be able to toggle.
BSStrategy = {
version: 2,
displayName: "MusicForProgramming",
accepts: {
method: "predicateOnTab",
format: "%K LIKE[c] '*musicforprogramming.net/*'",
args: ["URL"],
},
matches: [],
findElement: function (regex, tag) {
var elements = document.querySelectorAll(`nav ${tag}`);
if (!elements) return;
this.matches = Array.prototype.filter.call(elements, function (element) {
return RegExp(regex).test(element.textContent);
});
return this;
},
clickElement: function () {
const { matches } = this;
if (matches === undefined) return;
if (matches.length === 0) return;
matches[0].click();
return this;
},
isFound: function () {
return this.matches.length > 0;
},
isPlaying: function () {
return BSStrategy.findElement("stop", "button").isFound();
},
toggle: function () {
BSStrategy.findElement("(play|stop)", "> span").clickElement();
},
next: function () {
BSStrategy.findElement("next", "button").clickElement();
},
favorite: function () {
BSStrategy.findElement("favourite", "> span").clickElement();
},
previous: function () {
BSStrategy.findElement("prev", "button").clickElement();
},
pause: function () {
BSStrategy.findElement("stop", "button").clickElement();
},
trackInfo: function () {
var track = document.querySelector("#content .title");
return {
track: track ? track.innerText : "",
};
},
};