Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Hide last read chapter if there isn't any higher chapter (#21)
Browse files Browse the repository at this point in the history
Fix chapter highlight in chapter list
Remove debug variable
  • Loading branch information
Glagan committed Jan 18, 2020
1 parent 466e93c commit cd18826
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
12 changes: 12 additions & 0 deletions options.html
Expand Up @@ -188,6 +188,18 @@ <h1 class="text-container py-2 px-2"><i class="fas fa-bookmark"></i> Chapters li
</div>
</div>
</div>
<div class="form-group text-container p-2">
<label class="font-weight-bold">Hide <b>last read</b> chapter <a data-default="hideLastRead" class="btn btn-sm btn-secondary"><i class="fas fa-trash"></i><span class="d-none d-xl-inline"> Restore default</span></a></label>
<p class="d-none d-xl-block">Hide your last read chapter on MangaDex <b>if there isn't any higher chapter</b>.</p>
<div data-option="hideLastRead" data-type="checkbox" class="col px-0 my-auto input-group">
<div class="input-group-prepend">
<button type="button" class="btn btn-success input-prepend col px-2">Enabled</button>
</div>
<div class="input-group-append">
<button type="button" class="btn btn-secondary input-append col px-2 active">Disabled</button>
</div>
</div>
</div>
<div class="form-group text-container p-2">
<label class="font-weight-bold">Highlight chapters <a data-default="highlightChapters" class="btn btn-sm btn-secondary"><i class="fas fa-trash"></i><span class="d-none d-xl-inline"> Restore default</span></a></label>
<p class="d-none d-xl-block">If this option is disabled, no colors will be used. Does not prevent the <kbd>Hide lower chapters</kbd> and <kbd>Show tooltips</kbd> options to be applied.</p>
Expand Down
1 change: 1 addition & 0 deletions scripts/defaultOptions.js
Expand Up @@ -25,6 +25,7 @@ let defaultOptions = {
openedChaptersColor: "rgba(28, 135, 141, 0.4)",
hideLowerChapters: true,
hideHigherChapters: false,
hideLastRead: false,
saveOnlyHigher: true,
saveOnlyNext: false,
confirmChapter: true,
Expand Down
14 changes: 8 additions & 6 deletions scripts/myMangaDex.js
Expand Up @@ -502,7 +502,6 @@ class MyMangaDex {
let chaptersList = Array.from(document.querySelector(".chapter-container").children).reverse();

// Get the name of each "chapters" in the list - ignore first line
let zeroedChapter = Math.max(this.manga.lastMyAnimeListChapter, 0);
let hasChapterZero = false;
for (let i = 0; i < chaptersList.length - 1; i++) {
let element = chaptersList[i];
Expand Down Expand Up @@ -1028,6 +1027,7 @@ class MyMangaDex {
};
}
let chapter = this.getVolumeChapterFromNode(chapterRow);
chapter.value = chapter.chapter;
chapter.node = nodes[i];
currentGroup.chapters.push(chapter);
}
Expand Down Expand Up @@ -1168,12 +1168,14 @@ class MyMangaDex {
// If there is data
if (titleInformations[group.titleId]) {
let chapterCount = group.chapters.length;
let highestChapter = Math.max.apply(Math, group.chapters.map(e => { return e.value; }));
for (let j = 0; j < chapterCount; j++) {
let chapter = group.chapters[j];
let chapter = group.chapters[j];
if ((this.options.hideHigherChapters &&
titleInformations[group.titleId].last < chapter.value &&
chapter.value >= Math.floor(titleInformations[group.titleId].last) + 2) ||
this.options.hideLowerChapters && titleInformations[group.titleId].last > chapter.value) {
titleInformations[group.titleId].last < chapter.value &&
chapter.value >= Math.floor(titleInformations[group.titleId].last) + 2)
|| (this.options.hideLowerChapters && titleInformations[group.titleId].last > chapter.value)
|| (this.options.hideLastRead && chapter.value == highestChapter && titleInformations[group.titleId].last == chapter.value)) {
chapter.node.classList.add("is-hidden-chapter");
chapter.hidden = true;
}
Expand Down Expand Up @@ -1255,7 +1257,7 @@ class MyMangaDex {
let chapter = group.chapters[j];
chapter.node.classList.add("has-fast-in-transition");
if (titleInformations[group.titleId].last < chapter.value &&
chapter.value < Math.floor(titleInformations[group.titleId].last) + 2) {
chapter.value < Math.floor(titleInformations[group.titleId].last) + 2) {
paintRow(chapter.node, this.options.nextChapterColor);
group.selected = j;
outerColor = this.options.nextChapterColor;
Expand Down
2 changes: 1 addition & 1 deletion scripts/sharedFunctions.js
Expand Up @@ -169,7 +169,7 @@ async function loadOptions() {
SimpleNotification.info({
title: "Update 2.3.11",
image: mmdImage,
text: "Version **2.3.11** has been released, it should fix weird things with Ch.0/Oneshot.\nIf something else is now bugged because of that please report it."
text: "Version **2.3.11** has been released, it should fix weird things with Ch.0/Oneshot.\nIf something else is now bugged because of that please report it.\nYou can also hide the Last Read chapter in lists."
}, { sticky: true, position: "bottom-left" });
}
data.version = defaultOptions.version;
Expand Down

0 comments on commit cd18826

Please sign in to comment.