forked from nimsandu/spicetify-bloom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bloom.js
135 lines (123 loc) · 5.37 KB
/
bloom.js
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
(function bloom() {
function waitForElement(els, func, timeout = 10000) {
const queries = els.map(el => document.querySelector(el));
if (queries.every(a => a)) {
func();
} else if (timeout > 0) {
setTimeout(waitForElement, 300, els, func, timeout--);
}
}
waitForElement([
".main-rootlist-rootlistItem"
], function () {
function replacePlaylistIcons() {
const playListItems = document.getElementsByClassName("main-rootlist-rootlistItemLink");
const playListOverlay = document.querySelector("nav .main-rootlist-wrapper");
setInterval(() => {
waitForElement(["nav .main-rootlist-wrapper"], () => {
playListOverlay.style.height = `${playListItems.length * 63}px`;
})
}, 100);
for (const item of playListItems) {
const link = item.pathname;
let uri;
if (link.search("playlist") !== -1) {
uri = Spicetify.URI.playlistV2URI(link.split("/").pop());
} else if (link.search("folder") !== -1) {
item.style.WebkitMaskImage = "url('https://cdn.jsdelivr.net/gh/nimsandu/spicetify-bloom@master/assets/fluentui-system-icons/ic_fluent_folder_24_filled.svg')"
continue;
}
Spicetify.CosmosAsync.get(
`sp://core-playlist/v1/playlist/${uri.toString()}/metadata`, {
policy: {
picture: true
}
}
).then(res => {
const meta = res.metadata;
if (meta.picture === "") {
item.style.backgroundImage = "url('https://cdn.jsdelivr.net/gh/nimsandu/spicetify-bloom@master/assets/fluentui-system-icons/ic_fluent_music_note_2_24_filled.svg')"
} else {
item.style.backgroundImage = "url(" + meta.picture + ")";
item.style.content = "";
}
});
};
};
replacePlaylistIcons();
const observer = new MutationObserver(replacePlaylistIcons);
waitForElement(["#spicetify-playlist-list"], () => {
const rootList = document.querySelector("#spicetify-playlist-list");
observer.observe(rootList, {
childList: true,
subtree: true
});
});
});
waitForElement([
".main-navBar-navBarLink",
"[href='/collection'] > span"
], () => {
const navBarItems = document.getElementsByClassName("main-navBar-navBarLink");
for (const item of navBarItems) {
let div = document.createElement("div");
div.classList.add("navBar-navBarLink-accent");
item.appendChild(div);
}
document.querySelector("[href='/collection'] > span").innerHTML = "Library";
});
const textColor = getComputedStyle(document.documentElement).getPropertyValue('--spice-text');
if (textColor == " #000000") {
document.documentElement.style.setProperty('--filter-brightness', 0);
}
var interval = setInterval(function () {
if (
typeof Spicetify.Platform == 'undefined' || (
typeof Spicetify.Platform.Translations.play == 'undefined' &&
typeof Spicetify.Platform.Translations.pause == 'undefined'
)
) return;
clearInterval(interval);
var playButtonStyle = document.createElement('style');
playButtonStyle.type = 'text/css';
playButtonStyle.innerHTML = `
.main-playButton-button[aria-label="${Spicetify.Platform.Translations.play}"],
.main-playButton-PlayButton[aria-label="${Spicetify.Platform.Translations.play}"],
.main-playPauseButton-button[aria-label="${Spicetify.Platform.Translations.play}"],
.main-trackList-rowPlayPauseButton[aria-label="${Spicetify.Platform.Translations.play}"] {
background-color: var(--spice-text) !important;
-webkit-mask-image: url('https://cdn.jsdelivr.net/gh/nimsandu/spicetify-bloom@master/assets/fluentui-system-icons/ic_fluent_play_24_filled.svg') !important;
}
.main-playButton-button[aria-label="${Spicetify.Platform.Translations.pause}"],
.main-playButton-PlayButton[aria-label="${Spicetify.Platform.Translations.pause}"],
.main-playPauseButton-button[aria-label="${Spicetify.Platform.Translations.pause}"],
.main-trackList-rowPlayPauseButton[aria-label="${Spicetify.Platform.Translations.pause}"] {
background-color: var(--spice-text) !important;
-webkit-mask-image: url('https://cdn.jsdelivr.net/gh/nimsandu/spicetify-bloom@master/assets/fluentui-system-icons/ic_fluent_pause_16_filled.svg') !important;
}`;
document.getElementsByTagName('head')[0].appendChild(playButtonStyle);
}, 10)
waitForElement([".progress-bar__slider"], () => {
const sliders = document.getElementsByClassName("progress-bar__slider");
for (const slider of sliders) {
const dot = document.createElement("div");
dot.classList.add("slider-dot");
slider.appendChild(dot);
}
}, 10);
waitForElement([".ExtraControls"], () => {
const element = document.querySelector(".ExtraControls");
element.addEventListener("click", () => {
waitForElement([".npv-main-container .progress-bar__slider"], () => {
const sliders = document.getElementsByClassName("npv-main-container")[0].getElementsByClassName("progress-bar__slider");
for (const slider of sliders) {
if (slider.dataset.dot === "true") { continue; }
slider.dataset.dot = "true";
const dot = document.createElement("div");
dot.classList.add("slider-dot");
slider.appendChild(dot);
}
}, 10)
})
}, 10);
})();