Skip to content

Commit

Permalink
Update for pending show artist and year
Browse files Browse the repository at this point in the history
  • Loading branch information
kurotsmile committed Jul 8, 2024
1 parent 24c61bf commit f58017b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<li class="nav-item">
<a class="nav-link" href="https://apps.microsoft.com/detail/9pmh34z5twz2?hl=en-us&gl=US" target="_blank">Microsoft Store</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://carrotstore.itch.io/music-for-life" target="_blank">Itch.io</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://musica-para-la-vida.en.uptodown.com/android" target="_blank">uptodown</a>
</li>
Expand All @@ -38,7 +41,10 @@
</div>
</nav>
<div class="container">
<h1 class="mb-4"><img id="logo_app" src="images/logo.png" alt="Logo" id="logo"> Store Music <button class="btn btn-sm" onclick="donwload_artist()"><i class="fas fa-user-tie"></i> Artist</button></h1>
<h1 class="mb-4"><img id="logo_app" src="images/logo.png" alt="Logo" id="logo"> Store Music
<button class="btn btn-sm" onclick="donwload_artist()"><i class="fas fa-user-tie"></i> Artist</button>
<button class="btn btn-sm" onclick="donwload_year()"><i class="fas fa-user-tie"></i> Year</button>
</h1>
<div class="song-list" id="song-list">
<!-- Songs will be loaded here -->
</div>
Expand Down
51 changes: 40 additions & 11 deletions js/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,31 @@ var list_year=[];

$(document).ready(function() {

function addOrUpdateObjectToList(list_obj, data_obj_add) {
var addedOrUpdate = false;
for (var i = 0; i < list_obj.length; i++) {
if (list_obj[i].name === data_obj_add.name && list_obj[i].lang === data_obj_add.lang) {
list_obj[i].amount = (list_obj[i].amount || 0) + 1;
addedOrUpdate = true;
break;
}
}

if (!addedOrUpdate) {
data_obj_add.amount=1;
list_obj.push(data_obj_add);
}
}

$.getJSON("https://raw.githubusercontent.com/kurotsmile/Database-Store-Json/main/song.json", function(data) {
var songList = $("#song-list");
$.each(data.all_item, function(index, song) {
list_artist.push({"name":song.artist,"lang":song.lang});
var obj_artist={"name":song.artist,"lang":song.lang};
addOrUpdateObjectToList(list_artist,obj_artist);

var obj_year={"name":song.year,"lang":song.lang};
addOrUpdateObjectToList(list_year,obj_year);

var songItem = `<div class="song-item" data-src="${song.mp3}" data-title="${song.name}" data-artist="${song.artist}">
<img src="images/avatar_music.png" alt="Avatar" class="song-avatar">
<div class="song-title">${song.name}</div>
Expand Down Expand Up @@ -113,14 +134,22 @@ $(document).ready(function() {


function donwload_artist(){
var jsonString = JSON.stringify(list_artist);
var blob = new Blob([jsonString], { type: "application/json" });

var url = URL.createObjectURL(blob);

var a = document.createElement('a');
a.href = url;
a.download = 'song_artist.json';
a.click();
URL.revokeObjectURL(url);
download_json(list_artist,"song_artist.json");
}

function donwload_year(){
download_json(list_year,"song_year.json");
}

function download_json(data,file_name){
var jsonString = JSON.stringify(data);
var blob = new Blob([jsonString], { type: "application/json" });

var url = URL.createObjectURL(blob);

var a = document.createElement('a');
a.href = url;
a.download = file_name;
a.click();
URL.revokeObjectURL(url);
}

0 comments on commit f58017b

Please sign in to comment.