Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 46e063d

Browse filesBrowse files
committed
implemented all special functions for default playlists
1 parent 44c39ab commit 46e063d
Copy full SHA for 46e063d

10 files changed

+674-396Lines changed: 674 additions & 396 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎dist/NuoFlix/EnhancedNuoFlix.js‎

Copy file name to clipboardExpand all lines: dist/NuoFlix/EnhancedNuoFlix.js
+264-152Lines changed: 264 additions & 152 deletions
Large diffs are not rendered by default.
Collapse file

‎src/NuoFlix/EnhancedNuoFlix/Global/configs.js‎

Copy file name to clipboardExpand all lines: src/NuoFlix/EnhancedNuoFlix/Global/configs.js
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
/** @global */ const defaultPlaylists = [
2121
{ id: 1, is_custom: false, max_items: -1, name: 'Favoriten', item_cnt: 0, items: [], },
2222
{ id: 2, is_custom: false, max_items: -1, name: 'Für später gespeichert', item_cnt: 0, items: [], },
23-
{ id: 3, is_custom: false, max_items: -1, name: 'Zuletzt angesehene Videos', item_cnt: 0, items: [], },
23+
{ id: 3, is_custom: false, max_items: 10, name: 'Zuletzt angesehene Videos', item_cnt: 0, items: [], },
2424
];
2525

26+
// IDs of Playlists with special functions
27+
/** @global */ const favoritesID = 1;
28+
/** @global */ const watchLaterID = 2;
29+
/** @global */ const lastWatchedID = 3;
30+
2631
// Map execution flows to pages
2732
/** @global */ const pageRoutes = new Map([
2833
// path route name
Collapse file

‎src/NuoFlix/EnhancedNuoFlix/Global/functions_global.js‎

Copy file name to clipboardExpand all lines: src/NuoFlix/EnhancedNuoFlix/Global/functions_global.js
+59-26Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,16 @@ function iFrameReady(iframe, fn) {
419419
*
420420
* @requires playlistData
421421
*
422-
* @param {number} playlistId - Target playlist id
422+
* @param {(string|number)} playlistId - Target playlist id
423423
*
424424
* @return {?object} - Playlist object or null, if playlist is not found
425425
*/
426426
function getPlaylistObjectById(playlistId) {
427427
if (!playlistData) return null;
428+
if (typeof playlistId === 'string') playlistId = parseInt(playlistId);
428429
for (const playlist of playlistData) {
429-
if (playlist.id == playlistId) return playlist;
430+
if (typeof playlist.id === 'string') playlist.id = parseInt(playlist.id);
431+
if (playlist.id === playlistId) return playlist;
430432
}
431433
return null;
432434
}
@@ -438,41 +440,72 @@ function getPlaylistObjectById(playlistId) {
438440
*
439441
* @requires playlistData
440442
*
441-
* @param {Object} videoObject - Video object to add
442-
* @param {number} playlistId - Target playlist id
443+
* @param {(Object|number)} videoObject - Video object to add
444+
* @param {(Object|number)} playlist - Target playlist id or object
443445
*/
444-
function addVideoToPlaylist(videoObject, playlistId) {
445-
let playlist = getPlaylistObjectById(playlistId);
446-
if (!playlist) return;
446+
function addVideoToPlaylist(videoObject, playlist) {
447+
if (typeof playlist === 'number' || typeof playlist === 'string') playlist = getPlaylistObjectById(playlist);
448+
if (!(playlist) || typeof videoObject !== 'object') return;
449+
// if the video is already in the playlist (might occur in "last watched" or if something went wrong) then remove the odl entry
450+
const oldId = isVideoInPlaylist(videoObject.id, playlist);
451+
if (oldId !== false) playlist.items.deleteByIndex(oldId);
452+
// add the target video
447453
playlist.items.push(videoObject);
448-
playlist.item_cnt = 1 + playlist.item_cnt;
454+
// remove the oldest video from the list if playlist is full
455+
if (playlist.max_items !== -1 && playlist.items.length > playlist.max_items) playlist.items.shift();
456+
// update item count
457+
playlist.item_cnt = playlist.items.length;
458+
// update stored list
449459
set_value('playlistData', playlistData);
450460
}
451461

452462

453463

454464
/**
455-
* Removes the given video object to the target playlist and update the stored playlistData.
465+
* Removes the given video to the target playlist and update the stored playlistData.
456466
*
457467
* @requires playlistData
458468
*
459-
* @param {Object} videoObject - Video object to add
460-
* @param {number} playlistId - Target playlist id
469+
* @param {(Object|number)} video - Target video id or video object
470+
* @param {(Object|number)} playlist - Target playlist id or playlist object
461471
*/
462-
function removeVideoFromPlaylist(videoObject, playlistId) {
463-
let playlist = getPlaylistObjectById(playlistId);
464-
if (!playlist) return;
465-
466-
playlist.items.deleteByValue(videoObject);
467-
468-
//const oldItemList = Array.from(playlist.items);
469-
//let newItemList = [];
470-
//for (const item of oldItemList) {
471-
// if (item.id != videoObject.id) newItemList.push(item);
472-
//}
473-
//playlist.items = newItemList;
474-
475-
476-
playlist.item_cnt = 1 - playlist.item_cnt;
472+
function removeVideoFromPlaylist(video, playlist) {
473+
if (typeof video === 'object') video = video.id;
474+
if (typeof video === 'string') video = parseInt(video);
475+
if (typeof playlist !== 'object') playlist = getPlaylistObjectById(playlist);
476+
if (!(playlist) || !(video)) return;
477+
let index;
478+
for (let i = 0; i < playlist.items.length; i++) {
479+
if (parseInt(playlist.items[i].id) === video) {
480+
index = i;
481+
break;
482+
}
483+
}
484+
playlist.items.deleteByIndex(index);
485+
playlist.item_cnt = playlist.items.length;
477486
set_value('playlistData', playlistData);
478487
}
488+
489+
490+
491+
/**
492+
* Searches the playlist for the given video.
493+
*
494+
* @requires playlistData
495+
*
496+
* @param {(Object|number)} video - Target video id or video object
497+
* @param {(Object|number)} playlist - Target playlist id or playlist object
498+
*
499+
* @return {false|number} - Index of the video entry, if video is already stored in the playlist, false otherwise
500+
*/
501+
function isVideoInPlaylist(video, playlist) {
502+
if (typeof video === 'object') video = video.id;
503+
if (typeof video === 'string') video = parseInt(video);
504+
if (typeof playlist !== 'object') playlist = getPlaylistObjectById(playlist);
505+
if (!(playlist) || !(video)) return false;
506+
for (let i = 0; i < playlist.items.length; i++) {
507+
if (parseInt(playlist.items[i].id) === video) return i;
508+
}
509+
return false;
510+
}
511+
Collapse file

‎src/NuoFlix/EnhancedNuoFlix/ProfilePage/editPlaylistDialog.js‎

Copy file name to clipboardExpand all lines: src/NuoFlix/EnhancedNuoFlix/ProfilePage/editPlaylistDialog.js
+19-9Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
<div id="playlistDialog_middleLayer"></div>
33
<div id="editPlaylistDialog">
44
<div id="playlistNameWrapper" class="row">
5-
<input id="playlistName" class="col" type="text" maxlength="100" value="${playlist.name}" readonly="readonly" />
6-
<span id="changePlaylistName" class="col-auto" data-playlist-id="${playlist.id}">EDIT</span>
5+
<input id="playlistName" class="col" type="text" maxlength="100" value="${playlist.name}" readonly="readonly">
6+
<span id="changePlaylistName" class="col-auto" data-playlist-id="${playlist.id}">
7+
<svg xmlns="http://www.w3.org/2000/svg" height="1rem" width="1rem" class="svgColorized" viewBox="0 0 512 512">
8+
<path class="svgColoredFill" d="M410.3 231l11.3-11.3-33.9-33.9-62.1-62.1L291.7 89.8l-11.3 11.3-22.6 22.6L58.6 322.9c-10.4 10.4-18 23.3-22.2 37.4L1 480.7c-2.5 8.4-.2 17.5 6.1 23.7s15.3 8.5 23.7 6.1l120.3-35.4c14.1-4.2 27-11.8 37.4-22.2L387.7 253.7 410.3 231zM160 399.4l-9.1 22.7c-4 3.1-8.5 5.4-13.3 6.9L59.4 452l23-78.1c1.4-4.9 3.8-9.4 6.9-13.3l22.7-9.1v32c0 8.8 7.2 16 16 16h32zM362.7 18.7L348.3 33.2 325.7 55.8 314.3 67.1l33.9 33.9 62.1 62.1 33.9 33.9 11.3-11.3 22.6-22.6 14.5-14.5c25-25 25-65.5 0-90.5L453.3 18.7c-25-25-65.5-25-90.5 0zm-47.4 168l-144 144c-6.2 6.2-16.4 6.2-22.6 0s-6.2-16.4 0-22.6l144-144c6.2-6.2 16.4-6.2 22.6 0s6.2 16.4 0 22.6z"/>
9+
</svg>
10+
</span>
711
</div>
812
<ul id="videoList"></ul>
913
<div id="playlistDialogButtons" class="row">
10-
<a id="playlistDialogConfirmBtn" class="btn btn-small col-auto" data-playlist-id="${playlist.id}">${t('Bestätigen')}</a>
14+
<a id="playlistDialogConfirmBtn" class="btn btn-small col-auto disabled" data-playlist-id="${playlist.id}">${t('Bestätigen')}</a>
1115
<a id="playlistDialogCancelBtn" class="btn btn-small col-auto">${t('Abbrechen')}</a>
1216
</div>
1317
</div>
@@ -24,6 +28,8 @@
2428
}
2529
2630
#editPlaylistDialog {
31+
display: flex;
32+
flex-direction: column;
2733
position: fixed;
2834
width: min(max(30%, 14rem), max(80%, 20rem)); /* Target: 20rem, but min 30% (or at least 14rem) and max 80% */
2935
min-height: 14rem;
@@ -50,6 +56,9 @@
5056
cursor: default;
5157
text-overflow: ellipsis;
5258
}
59+
#changePlaylistName:hover .svgColoredFill {
60+
filter: brightness(2);
61+
}
5362
5463
#changePlaylistName {
5564
margin: auto 0 auto 1rem;
@@ -66,13 +75,10 @@
6675
padding: .3rem;
6776
}
6877
69-
.videoListEntry {
70-
71-
}
72-
7378
.videoListEntry_NameRow {
7479
display: flex;
75-
flex-wrap: nowrap;
80+
flex-wrap: nowrap
81+
cursor: default;
7682
}
7783
7884
.videoListEntry_id {
@@ -89,7 +95,6 @@
8995
9096
.videoListEntry_delete {
9197
margin-inline: 1rem;
92-
9398
}
9499
95100
.videoListEntry_delete:hover {
@@ -103,6 +108,11 @@
103108
104109
#playlistDialogButtons {
105110
justify-content: center;
111+
margin-block: auto .75rem;
112+
}
113+
114+
#noVideosInfo {
115+
margin-inline: auto;
106116
}
107117
</style>
108118
`.parseHTML();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.