Skip to content

Commit

Permalink
Scanlator filter
Browse files Browse the repository at this point in the history
  • Loading branch information
BrutuZ committed Nov 11, 2024
1 parent d67a348 commit dc4bfee
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
5 changes: 4 additions & 1 deletion site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ <h2>Load your .tachibk, .proto.gz or extracted .json file</h2>
</div>
<ul id="manga-genres"></ul>
</div>
<span class="material-symbols-outlined" id="chapters-sort-button">swap_vert</span>
<div id="chapter-buttons">
<span class="material-symbols-outlined" id="chapters-sort-button">swap_vert</span>
<span class="material-symbols-outlined" id="chapters-filter-button">filter_list</span>
</div>
<div id="manga-chapters"></div>
</div>
</div>
Expand Down
10 changes: 9 additions & 1 deletion site/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import consts from './scripts/constants.js';
import { dlJSON, encodeToProtobuf } from './scripts/export.js';
import { handleFileLoad, loadDemoData } from './scripts/loadBackup.js';
import { closeModal, showModal } from './scripts/modals.js';
import { initializeLibrary, toggleExpandDescription } from './scripts/library.js';
import {
initializeLibrary,
toggleChapterFilter,
toggleExpandDescription,
} from './scripts/library.js';
import { applySettings, loadSettings, saveSetting } from './scripts/settings.js';

var searchCooldown;
Expand All @@ -28,6 +32,10 @@ document.addEventListener('DOMContentLoaded', () => {
},
});
}); // Sort chapters
consts.chapterFilterButton.addEventListener('click', event => {
event.target.classList.toggle('active');
toggleChapterFilter();
});
consts.loadBackup.addEventListener('click', e => {
closeModal('settings-modal');
window.data = null;
Expand Down
1 change: 1 addition & 0 deletions site/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default {
modalDescriptionDiv: document.querySelector('#manga-description-div'),
expandDescriptionArrow: document.querySelector('.fade-out'),
sortButton: document.querySelector('#chapters-sort-button'),
chapterFilterButton: document.querySelector('#chapters-filter-button'),
chapterList: document.querySelector('#manga-chapters'),
// Main Screen
tabsContainer: document.querySelector('#tabs'),
Expand Down
14 changes: 14 additions & 0 deletions site/scripts/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ function showMangaDetails(manga, categories, source) {
const repoMatch = repoData?.find(entry => entry.id == manga.source);
const newWindowIcon = addMaterialSymbol(null, 'open_in_new');
newWindowIcon.classList.add('link-icon');
consts.mangaModal.dataset.index = window.data.backupManga.indexOf(manga);
consts.modalTitle.forEach(element => {
element.textContent = manga.customTitle || manga.title;
element.parentNode.removeAttribute('href');
Expand Down Expand Up @@ -528,6 +529,9 @@ function showMangaDetails(manga, categories, source) {
consts.sortButton.hidden = false;
} else consts.sortButton.hidden = true;

consts.chapterFilterButton.hidden = !Array.isArray(manga.excludedScanlators);
toggleChapterFilter();

showModal('manga-modal');
consts.expandDescriptionArrow.hidden =
consts.modalDescriptionDiv.offsetHeight <
Expand Down Expand Up @@ -792,3 +796,13 @@ function getRepoIndex() {
});
return sources;
}

export function toggleChapterFilter() {
const manga = window.data.backupManga[consts.mangaModal.dataset.index];
const scanlators = manga.excludedScanlators || [];
document.querySelectorAll('.scanlator').forEach(element => {
element.closest('.chapter-box').hidden = consts.chapterFilterButton.classList.contains('active')
? scanlators.includes(element.textContent)
: false;
});
}
12 changes: 11 additions & 1 deletion site/styles/manga-details.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,23 @@
flex-flow: column-reverse;
}

#chapter-buttons {
display: flex;
flex-direction: row-reverse;
}

#chapters-filter-button,
#chapters-sort-button {
cursor: pointer;
display: block;
margin: 0;
margin: 0 0 0 0.5em;
text-align: right;
}

#chapters-filter-button.active {
color: var(--color-filter-active);
}

#manga-title-link,
#manga-source > a,
#manga-chapters a {
Expand Down

0 comments on commit dc4bfee

Please sign in to comment.