-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalSearch.js
More file actions
45 lines (44 loc) · 1.59 KB
/
localSearch.js
File metadata and controls
45 lines (44 loc) · 1.59 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
(function localFileSearch() {
if (!window.Spicetify) {
setTimeout(localFileSearch, 300);
return;
}
const required = {
ContextMenu: 'Item',
Player: 'data',
Platform: 'History',
showNotification: ''
};
const isReady = Object.entries(required).every(([key, prop]) => {
return Spicetify[key] && (prop ? Spicetify[key][prop] : true);
});
if (!isReady) {
setTimeout(localFileSearch, 300);
return;
}
function searchForTrack(uri) {
const parts = uri.split(":");
const [_, __, artistRaw, ___, titleRaw] = parts;
const artist = decodeURIComponent(artistRaw || "").replace(/\+/g, " ");
const title = decodeURIComponent(titleRaw || "").replace(/\+/g, " ");
const query = `${artist} ${title}`.trim();
Spicetify.Platform.History.push({
pathname: '/search/' + encodeURIComponent(query),
search: '?type=track'
});
Spicetify.showNotification(`Searching for: ${query}`);
}
function shouldShowMenu(uris) {
return uris?.[0]?.startsWith("spotify:local:");
}
try {
new Spicetify.ContextMenu.Item(
'Search for this local track',
(uris) => searchForTrack(uris[0]),
shouldShowMenu,
'search'
).register();
} catch (e) {
console.error('Context menu registration failed:', e);
}
})();