(function() {
'use strict';
const $ = window.jQuery;
if (window.location.href.indexOf('score_list') > 0) {
scoreListFilter();
}
function scoreListFilter(){
let activeCrown = localStorage.getItem('activeCrown') || null;
let activeUra = localStorage.getItem('activeUra') || null;
let searchQuery = '';
const buttonsHtml = `
`;
$('#tabList').append(buttonsHtml);
// 曲情報の取得
const songList = [];
$('.contentBox').each(function(){
const songName = $(this).find('.songName, .songNameFontkids').text().trim();
const crownImg = $(this).find('.buttonList li:nth-child(4) a img').attr('src') || '';
let crownStatus = 'none';
if(crownImg.indexOf('donderfull') > 0) crownStatus = 'donderfull';
else if(crownImg.indexOf('gold') > 0) crownStatus = 'gold';
else if(crownImg.indexOf('silver') > 0) crownStatus = 'silver';
else if(crownImg.indexOf('played') > 0) crownStatus = 'played';
const isUra = $(this).find('.songNameArea.ura.clearfix').length > 0;
songList.push({
element: $(this),
songName: songName,
crown: crownStatus,
ura: isUra
});
});
function updateFilter() {
songList.forEach(item => {
let show = true;
if(activeCrown && item.crown !== activeCrown) show = false;
if(activeUra && ((activeUra === 'ura' && !item.ura) || (activeUra === 'normal' && item.ura))) show = false;
if(searchQuery && !item.songName.toLowerCase().includes(searchQuery.toLowerCase())) show = false;
if(show) item.element.show();
else item.element.hide();
});
}
function restoreButtonState() {
$('.crownBtn').each(function(){
if($(this).data('crown') === activeCrown){
$(this).css({'background':'#ff9800','border-color':'#fff'});
} else {
$(this).css({'background':'#444','border-color':'#222'});
}
});
$('.uraBtn').each(function(){
if($(this).data('ura') === activeUra){
$(this).css({'background':'#ff9800','border-color':'#fff'});
} else {
$(this).css({'background':'#444','border-color':'#222'});
}
});
updateFilter();
}
restoreButtonState();
// ボタンクリック
$('.crownBtn').click(function(){
const selected = $(this).data('crown');
if(activeCrown === selected){
activeCrown = null;
} else {
activeCrown = selected;
}
localStorage.setItem('activeCrown', activeCrown);
restoreButtonState();
});
$('.uraBtn').click(function(){
const selected = $(this).data('ura');
if(activeUra === selected){
activeUra = null;
} else {
activeUra = selected;
}
localStorage.setItem('activeUra', activeUra);
restoreButtonState();
});
// 検索ボックス
$('#songSearchInput').on('input', function(){
searchQuery = $(this).val().trim();
updateFilter();
});
}
})();