-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlaylistTemplate.html
439 lines (358 loc) · 18 KB
/
PlaylistTemplate.html
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
:root
{
color-scheme: light dark; /* Opt the entire page into the user's color scheme preferences */
}
html
{
margin: 0;
padding: 0;
}
body
{
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0 auto;
padding: 0;
font: 90% Calibri, Sans-serif;
line-height: 1.2;
color: #555753;
/* background-color: #e0e0e0; *//* Don't set a background color to use the theme background color of the foobar2000 panel */
}
div
{
display: none;
margin-top: 0;
text-align: center;
display: inline;
}
.track
{
font: 1.75em Cambria;
color: crimson;
}
.artist
{
font: 1.00em Cambria;
color: crimson;
}
.value
{
font-weight: 800;
}
</style>
</head>
<body>
<div>
Playlist count: <span id="playlistCount"></span><br/>
Active playlist: <span id="activePlaylist"></span><br/>
Playing playlist: <span id="playingPlaylist"></span><br/>
Playlist name: <span id="playlistName"></span><br/>
Focused playlist item: <span id="focusedPlaylistItem"></span><br/>
<br/>
onPlaylistItemsAdded: <span id="onPlaylistItemsAddedResult"></span><br/>
onPlaylistItemsReordered: <span id="onPlaylistItemsReorderedResult"></span><br/>
onPlaylistItemsRemoving: <span id="onPlaylistItemsRemovingResult"></span><br/>
onPlaylistItemsRemoved: <span id="onPlaylistItemsRemovedResult"></span><br/>
<br/>
onPlaylistItemEnsureVisible: <span id="onPlaylistItemEnsureVisibleResult"></span><br/>
onPlaylistItemsModified: <span id="onPlaylistItemsModifiedResult"></span><br/>
onPlaylistItemsModifiedFromPlayback: <span id="onPlaylistItemsModifiedFromPlaybackResult"></span><br/>
onPlaylistItemsReplaced: <span id="onPlaylistItemsReplacedResult"></span><br/>
<br/>
onPlaylistCreated: <span id="onPlaylistCreatedResult"></span><br/>
onPlaylistActivated: <span id="onPlaylistActivatedResult"></span><br/>
onPlaylistRenamed: <span id="onPlaylistRenamedResult"></span><br/>
onPlaylistLocked: <span id="onPlaylistLockedResult"></span><br/>
onPlaylistUnlocked: <span id="onPlaylistUnlockedResult"></span><br/>
onPlaylistSelectedItemsChanged: <span id="onPlaylistSelectedItemsChangedResult"></span><br/>
onPlaylistFocusedItemChanged: <span id="onPlaylistFocusedItemChangedResult"></span><br/>
<br/>
onPlaylistsReordered: <span id="onPlaylistsReorderedResult"></span><br/>
onPlaylistsRemoving: <span id="onPlaylistsRemovingResult"></span><br/>
onPlaylistsRemoved: <span id="onPlaylistsRemovedResult"></span><br/>
<br/>
onDefaultFormatChanged: <span id="onDefaultFormatChangedResult"></span><br/>
<br/>
onPlaybackOrderChanged: <span id="onPlaybackOrderChangedResult"></span><br/>
<br/>
<button id="createPlaylistButton">Create Playlist</button>
<button id="duplicatePlaylistButton">Duplicate Playlist</button>
<button id="findPlaylistButton">Find Playlist</button><br/>
<button id="deletePlaylistButton">Delete Playlist</button>
<br/>
<button id="getPlaylistItemsButton">Get Playlist Items</button>
<button id="getSelectedItemsButton">Get Selected Playlist Items</button><br/>
<br/>
<div id="Playlist"/>
Select last item <button id="selectItemButton">Execute</button> <span id="selectItemResult"></span><br/>
Deselect last item <button id="deselectItemButton">Execute</button> <span id="deselectItemResult"></span><br/>
Is last item selected? <button id="isSelectedButton">Execute</button> <span id="isSelectedResult"></span><br/>
Remove selected playlist items <button id="removeSelectedButton">Execute</button> <span id="removeSelectedResult"></span><br/>
Remove unselected playlist items <button id="removeUnselectedButton">Execute</button> <span id="removeUnselectedResult"></span><br/>
Count playlist items <button id="playlistItemCountButton">Execute</button> <span id="playlistItemCount"></span><br/>
Count selected playlist items <button id="selectedPlaylistItemCountButton">Execute</button> <span id="selectedPlaylistItemCount"></span><br/>
Remove last item <button id="removeItemButton">Execute</button> <span id="removeItemResult"></span><br/>
<br/>
Clear playlist <button id="clearPlaylistButton">Execute</button> <span id="clearPlaylistResult"></span><br/>
<br/>
Create Auto playlist <button id="createAutoPlaylistButton">Execute</button> <span id="createAutoPlaylistResult"></span><br/>
Is auto playlist: <span id="isAutoPlaylist"></span><br/>
<br/>
Playback order: <span id="playbackOrder"></span><br/>
<br/>
<button id="readImageButton">Read Image</button><br/>
<br/>
<div width="128px" height="128px" style="overflow: hidden;">
<img id="readImageResult" style="max-width: 128px; height: auto; object-fit: cover;"/><br/>
</div>
<button id="readDirectoryButton">Read Directory</button><br/>
<br/>
<div id="readDirectoryResult"/>
</div>
<script>
// Refreshes the content of all elements.
function Refresh()
{
const Index = chrome.webview.hostObjects.sync.foo_uie_webview.activePlaylist;
document.getElementById("playlistCount").textContent = chrome.webview.hostObjects.sync.foo_uie_webview.playlistCount;
document.getElementById("activePlaylist").textContent = Index;
document.getElementById("playingPlaylist").textContent = chrome.webview.hostObjects.sync.foo_uie_webview.playingPlaylist;
document.getElementById("playlistName").textContent = chrome.webview.hostObjects.sync.foo_uie_webview.getPlaylistName(Index);
document.getElementById("focusedPlaylistItem").textContent = chrome.webview.hostObjects.sync.foo_uie_webview.getFocusedPlaylistItem(Index);
document.getElementById("isAutoPlaylist").textContent = chrome.webview.hostObjects.sync.foo_uie_webview.isAutoPlaylist(Index);
document.getElementById("playbackOrder").textContent = chrome.webview.hostObjects.sync.foo_uie_webview.playbackOrder;
}
document.getElementById("createPlaylistButton").addEventListener("click", async () =>
{
// Create a new playlist with an auto-generated name after the last playlist and activate it.
chrome.webview.hostObjects.sync.foo_uie_webview.activePlaylist = await chrome.webview.hostObjects.foo_uie_webview.createPlaylist(-1, "");
// Add a new item to the active playlist after the last item using a location and select the newly added item.
await chrome.webview.hostObjects.foo_uie_webview.addPath(-1, -1, "file:////C:\\Test 1.mp3", true);
await chrome.webview.hostObjects.foo_uie_webview.addPath(-1, -1, "file:////C:\\Test 2.mp3", true);
Refresh();
});
document.getElementById("duplicatePlaylistButton").addEventListener("click", async () =>
{
// Create a duplicate of playlist 0.
const PlaylistIndex = await chrome.webview.hostObjects.foo_uie_webview.duplicatePlaylist(0, "Duplicate");
// Activate the new playlist.
chrome.webview.hostObjects.sync.foo_uie_webview.activePlaylist = PlaylistIndex;
// Ensure that the last playlist item is visible.
chrome.webview.hostObjects.foo_uie_webview.ensurePlaylistItemVisible(PlaylistIndex, chrome.webview.hostObjects.sync.foo_uie_webview.getPlaylistItemCount(PlaylistIndex) - 1);
});
document.getElementById("findPlaylistButton").addEventListener("click", async () =>
{
// Find the playlist named "Duplicate" and activate it.
chrome.webview.hostObjects.sync.foo_uie_webview.activePlaylist = await chrome.webview.hostObjects.foo_uie_webview.findPlaylist("Duplicate");
});
document.getElementById("deletePlaylistButton").addEventListener("click", async () =>
{
// Deletes the specified playlist. Use -1 for the active playlist.
await chrome.webview.hostObjects.foo_uie_webview.deletePlaylist(-1);
});
document.getElementById("getPlaylistItemsButton").addEventListener("click", async () =>
{
// Gets the items of the specified playlist as an array of locations.
const Text = await chrome.webview.hostObjects.foo_uie_webview.getPlaylistItems(0);
const Items = JSON.parse(Text);
document.getElementById('Playlist').innerHTML = ArrayToTable(Items);
});
document.getElementById("getSelectedItemsButton").addEventListener("click", async () =>
{
const Text = await chrome.webview.hostObjects.foo_uie_webview.getSelectedPlaylistItems(0);
const Items = JSON.parse(Text);
document.getElementById('Playlist').innerHTML = ArrayToTable(Items);
});
document.getElementById("selectItemButton").addEventListener("click", async () =>
{
// Selects the last item of the active playlist.
await chrome.webview.hostObjects.foo_uie_webview.selectPlaylistItem(-1, -1);
document.getElementById("selectItemResult").textContent = "Done (" + Now() + ")";
});
document.getElementById("deselectItemButton").addEventListener("click", async () =>
{
// Deselects the last item of the active playlist.
await chrome.webview.hostObjects.foo_uie_webview.deselectPlaylistItem(-1, -1);
document.getElementById("deselectItemResult").textContent = "Done (" + Now() + ")";
});
document.getElementById("isSelectedButton").addEventListener("click", async () =>
{
// Returns true if the last item of the active playlist is selected.
document.getElementById("isSelectedResult").textContent = await chrome.webview.hostObjects.foo_uie_webview.isPlaylistItemSelected(-1, -1);
});
document.getElementById("removeSelectedButton").addEventListener("click", async () =>
{
await chrome.webview.hostObjects.foo_uie_webview.removeSelectedPlaylistItems(0);
document.getElementById("removeSelectedResult").textContent = "Done (" + Now() + ")";
});
document.getElementById("removeUnselectedButton").addEventListener("click", async () =>
{
await chrome.webview.hostObjects.foo_uie_webview.removeUnselectedPlaylistItems(0);
document.getElementById("removeUnselectedResult").textContent = "Done (" + Now() + ")";
});
document.getElementById("playlistItemCountButton").addEventListener("click", async () =>
{
document.getElementById("playlistItemCount").textContent = chrome.webview.hostObjects.sync.foo_uie_webview.getPlaylistItemCount(-1);
});
document.getElementById("selectedPlaylistItemCountButton").addEventListener("click", async () =>
{
document.getElementById("selectedPlaylistItemCount").textContent = chrome.webview.hostObjects.sync.foo_uie_webview.getSelectedPlaylistItemCount(-1, -1);
});
document.getElementById("removeItemButton").addEventListener("click", async () =>
{
await chrome.webview.hostObjects.foo_uie_webview.removePlaylistItem(-1, -1);
document.getElementById("removeItemResult").textContent = "Done (" + Now() + ")";
});
document.getElementById("clearPlaylistButton").addEventListener("click", async () =>
{
// Clear the specified playlist. Use -1 for the active playlist.
await chrome.webview.hostObjects.foo_uie_webview.clearPlaylist(-1);
document.getElementById("clearPlaylistResult").textContent = "Done (" + Now() + ")";
});
document.getElementById("createAutoPlaylistButton").addEventListener("click", async () =>
{
chrome.webview.hostObjects.sync.foo_uie_webview.activePlaylist = await chrome.webview.hostObjects.foo_uie_webview.createAutoPlaylist(-1, "Test", "%title% HAS test", "%album artist% | %album% | %tracknumber% | %title%", 0);
document.getElementById("createAutoPlaylistResult").textContent = "Done (" + Now() + ")";
});
document.getElementById("readImageButton").addEventListener("click", async () =>
{
document.getElementById("readImageResult").src = await chrome.webview.hostObjects.foo_uie_webview.readImage("C:/Windows/Web/Screen/img100.jpg");
});
document.getElementById("readDirectoryButton").addEventListener("click", async () =>
{
const Text = await chrome.webview.hostObjects.foo_uie_webview.readDirectory("C:/Windows" /*, "*.exe" */);
const Items = JSON.parse(Text);
document.getElementById("readDirectoryResult").innerHTML = ArrayToTable(Items);
});
// Called when items have been added to the specified playlist.
function onPlaylistItemsAdded(playlistIndex, startIndex, locations)
{
document.getElementById("onPlaylistItemsAddedResult").textContent = "Items added at index " + startIndex + " to playlist " + playlistIndex + " (" + Now() + ")";
const Items = JSON.parse(locations);
document.getElementById("readDirectoryResult").innerHTML = ArrayToTable(Items);
}
// Called when the items of the specified playlist have been reordered.
function onPlaylistItemsReordered(playlistIndex, items)
{
document.getElementById("onPlaylistItemsReorderedResult").textContent = "Items of playlist " + playlistIndex + " have been reordered as " + items + " (" + Now() + ")";
}
// Called when removing items from the specified playlist.
function onPlaylistItemsRemoving(playlistIndex, removedItems, newCount)
{
document.getElementById("onPlaylistItemsRemovingResult").textContent = "Items " + removedItems + " being removed from playlist " + playlistIndex + " (" + Now() + ")";
}
// Called when items have been removed from the specified playlist.
function onPlaylistItemsRemoved(playlistIndex, removedItems, newCount)
{
document.getElementById("onPlaylistItemsRemovedResult").textContent = "Items " + removedItems + " removed from playlist " + playlistIndex + " (" + Now() + ")";
}
// Called when some playlist items of the specified playlist have been modified.
function onPlaylistItemsModified(playlistIndex, items)
{
document.getElementById("onPlaylistItemsModifiedResult").textContent = "Playlist items " + items + " have been modified in playlist " + playlistIndex + " (" + Now() + ")";
}
// Called when some playlist items of the specified playlist have been modified from playback.
function onPlaylistItemsModifiedFromPlayback(playlistIndex, items)
{
document.getElementById("onPlaylistItemsModifiedFromPlaybackResult").textContent = "Playlist items " + items + " have been modified from playback in playlist " + playlistIndex + " (" + Now() + ")";
}
// Called when items of the specified playlist have been replaced.
function onPlaylistItemsReplaced(playlistIndex, items)
{
document.getElementById("onPlaylistItemsReplacedResult").textContent = "Playlist items " + items + "have been replaced in playlist " + playlistIndex + " (" + Now() + ")";
}
// Called when the specified item of a playlist has been ensured to be visible.
function onPlaylistItemEnsureVisible(playlistIndex, itemIndex)
{
document.getElementById("onPlaylistItemEnsureVisibleResult").textContent = "Ensured item " + itemIndex + " in playlist " + playlistIndex + " (" + Now() + ")";
}
// Called when a new playlist has been created.
function onPlaylistCreated(playlistIndex, name)
{
document.getElementById("onPlaylistCreatedResult").textContent = "Created playlist " + playlistIndex + " as \"" + name + "\" (" + Now() + ")";
}
// Called when the specified playlist has been renamed.
function onPlaylistRenamed(playlistIndex, name)
{
document.getElementById("onPlaylistRenamedResult").textContent = "Playlist " + playlistIndex + " renamed to \"" + name + "\" (" + Now() + ")";
}
// Called when the active playlist changes.
function onPlaylistActivated(oldPlaylistIndex, newPlaylistIndex)
{
document.getElementById("onPlaylistActivatedResult").textContent = "Active playlist changed from " + oldPlaylistIndex + " to " + newPlaylistIndex + " (" + Now() + ")";
}
// Called when the specified playlist has been locked.
function onPlaylistLocked(playlistIndex)
{
document.getElementById("onPlaylistLockedResult").textContent = "Playlist " + playlistIndex + " has been locked (" + Now() + ")";
}
// Called when the specified playlist has been locked.
function onPlaylistUnlocked(playlistIndex)
{
document.getElementById("onPlaylistUnlockedResult").textContent = "Playlist " + playlistIndex + " has been unlocked (" + Now() + ")";
}
// Called when the selected items changed.
function onPlaylistSelectedItemsChanged(playlistIndex, selectedItems)
{
document.getElementById("onPlaylistSelectedItemsChangedResult").textContent = "Selected items changed to " + selectedItems + " in playlist " + playlistIndex + " (" + Now() + ")";
}
// Called when the focused item of a playlist changed.
function onPlaylistFocusedItemChanged(playlistIndex, fromIndex, toIndex)
{
document.getElementById("onPlaylistFocusedItemChangedResult").textContent = "Focused item changed from " + fromIndex + " to " + toIndex + " in playlist " + playlistIndex + " (" + Now() + ")";
}
// Called when the playlists have been reordered.
function onPlaylistsReordered(playlistOrder)
{
document.getElementById("onPlaylistsReorderedResult").textContent = "Playlists " + playlistOrder + " have been reordered (" + Now() + ")";
}
// Called when playlists are being removed.
function onPlaylistsRemoving(removedPlaylists, newCount)
{
document.getElementById("onPlaylistsRemovingResult").textContent = "Playlists " + removedPlaylists + " are being removed (" + Now() + ")";
}
/// Called when playlists have been removed.
function onPlaylistsRemoved(removedPlaylists, newCount)
{
document.getElementById("onPlaylistsRemovedResult").textContent = "Playlists " + removedPlaylists + " have been removed (" + Now() + ")";
}
/// Called when the default format has been changed.
function onDefaultFormatChanged()
{
document.getElementById("onDefaultFormatChangedResult").textContent = "Default format has been changed (" + Now() + ")";
}
/// Called when the playback order changed.
function onPlaybackOrderChanged(playbackOrderIndex)
{
document.getElementById("onPlaybackOrderChangedResult").textContent = "Playback order changed to " + playbackOrderIndex + " (" + Now() + ")";
}
function ArrayToTable(Items)
{
const Headers = Object.keys(Items[0]);
let Table = '<table><thead><tr>';
Headers.forEach(Header => Table += `<th>${Header}</th>`);
Table += '</tr></thead><tbody>';
Items.forEach(Row =>
{
Table += '<tr>';
Headers.forEach(Header => Table += `<td>${Row[Header]}</td>`);
Table += '</tr>';
});
Table += '</tbody></table>';
return Table;
}
function Now()
{
return new Date().toISOString().slice(-24).replace(/\D/g,'').slice(0, 14);
}
Refresh();
</script>
</body>
</html>