Skip to content

Commit

Permalink
Фильтр по недавно игравшим трекам
Browse files Browse the repository at this point in the history
  • Loading branch information
Chimildic committed May 22, 2021
1 parent 9836439 commit 0b3b19c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "__MSG_ext_name__",
"short_name": "__MSG_ext_short_name__",
"description": "__MSG_ext_description__",
"version": "0.7.1",
"version": "0.7.2",
"manifest_version": 2,
"author": "Chimildic",
"default_locale": "ru",
Expand Down
7 changes: 7 additions & 0 deletions page/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ <h2>Список изменений YaMuTools</h2>
<a class="button" target="_blank" href="/page/feedback.html">Обратная связь</a>
<p id="author">Chimildic, 2021</p>
</footer>
<section class="bubble">
<h3>Версия 0.7.2</h3>
<hr />
<ul>
<li>В фильтре треков плейлиста появилась возможность удалить недавно игравшие треки (из истории прослушиваний)</li>
</ul>
</section>
<section class="bubble">
<h3>Версия 0.7.1</h3>
<hr />
Expand Down
40 changes: 40 additions & 0 deletions script/tool/playlist/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const FILTER_CONTEXT_MENU = {
title: 'Управление ремиксами',
handler: () => onClickFilterTool(onClickControlMixTracks),
},
{
title: 'Удалить недавно игравшие',
handler: () => onClickFilterTool(onClickRemoveHistoryTracks),
},
{
title: 'Удалить с пометкой "Е"',
handler: () => onClickFilterTool(onClickRemoveExplicitTracks),
Expand Down Expand Up @@ -113,6 +117,42 @@ function onClickRemoveRuTracks(playlist) {
updateTracksWithFilter(playlist);
}

async function onClickRemoveHistoryTracks(playlist) {
Swal.fire({
title: 'История прослушиваний',
input: 'text',
text: 'Сколько недавних треков из истории учитывать?',
inputValue: 500,
showCancelButton: true,
cancelButtonText: 'Отмена',
inputValidator: (value) => {
if (!/^[1-9]\d*$/.test(value)) {
return 'Некорректное число';
}
}
}).then(result => {
if (!result.isConfirmed) {
return;
}

receiveHistory((response) => {
if (!response.hasTracks) {
fireInfoSwal('В истории прослушиваний нет треков.');
return;
}

response.trackIds.length = parseInt(result.value);
playlist.tracks = playlist.tracks.filter((track) => {
if (!track.id || !track.albums || track.albums.length == 0) {
return false;
}
return !response.trackIds.includes(`${track.id}:${track.albums[0].id}`);
});
updateTracksWithFilter(playlist);
});
});
}

function updateTracksWithFilter(playlist, ids) {
let trackIds = ids || getTrackIds(playlist.tracks);
if (playlist.trackCount == trackIds.length) {
Expand Down

0 comments on commit 0b3b19c

Please sign in to comment.