Skip to content
Permalink
Browse files

Fix MyAnimeList not found inside title page while reading

Updated Online Save to save history title volume progress
History progress now save volume again
Fix export online function
Fix history page
Shortened some notifications
Rephrased online import/export warning
Build options for debug
  • Loading branch information...
Glagan committed Aug 17, 2019
1 parent e1a9ee6 commit cc22a4d2aae51264c9f4a310c8d7ede658c64ce8
Showing with 89 additions and 30 deletions.
  1. +6 −1 README.md
  2. +27 −4 build.js
  3. +2 −2 options.html
  4. +1 −1 scripts/defaultOptions.js
  5. +6 −3 scripts/myMangaDex.js
  6. +21 −15 scripts/optionsManager.js
  7. +26 −4 scripts/sharedFunctions.js
@@ -86,7 +86,12 @@ You can disable the option to save all opened chapters, and all of the data can
## Debug installation

You can also install the extension from this repository, but the extension **will** be uninstalled when Firefox is closed and the data **could** be deleted at the same time, Chrome will keep the extension installed.
Before you actually install it, you have to build it, using ``node build <browser>``, ``rimraf``, ``babel-minify`` and ``web-ext`` are required.
Before you actually install it, you have to build it, using ``node build <browser>``, ``rimraf``, ``terser`` and ``web-ext`` are required.

Options:

* ``-no-minify``: Don't use **terser** to minify scripts.
* ``-debug``: Add a global try catch block.

### Firefox

@@ -12,7 +12,7 @@ const [,, ...args] = process.argv;
let manifest = {
manifest_version: 2,
name: "MyMangaDex",
version: "2.2",
version: "2.2.1",
author: "Glagan",

description: "Automatically update your MyAnimeList manga list when reading on MangaDex.",
@@ -114,6 +114,19 @@ if (args[0] == "firefox" || args[0] == "f") {
browser = "chrome";
}

// Options
let noMinify = false;
if (args.indexOf('-no-minify') >= 0) {
noMinify = true;
}
let debug = false;
if (args.indexOf('-debug') >= 0) {
debug = true;
}

console.log("Building for", browser);
console.log("Options: no-minify[" + noMinify + "] debug[" + debug + "]\n");

// Browser specific elements
if (browser == "firefox") {
// Add gecko id
@@ -182,9 +195,19 @@ if (["firefox", "chrome"].includes(browser)) {
scripts[name].forEach(filename => {
scriptConcatContent.push(fs.readFileSync(filename, "utf-8"));
});
const minified = Terser.minify(scriptConcatContent, {
ie8: false
});
let minified = 0;
if (noMinify) {
minified = { code: scriptConcatContent.join("\n") };
} else {
minified = Terser.minify(scriptConcatContent, {
ie8: false
});
}
if (debug) {
minified.code = [
"try {\n", minified.code, "\n} catch(e) {\n\tconsole.error(e);\n}"
].join("")
}
let scriptFileStream = fs.createWriteStream(makeFolder + "/scripts/" + name, { flags: "w+" });
scriptFileStream.write(minified.code);
scriptFileStream.cork();
@@ -362,8 +362,8 @@ <h1 class="text-container py-2 px-2"><i class="fas fa-globe"></i> Online Save</h
<!-- Logged in -->
<div id="loggedInPanel" class="text-container p-2 mb-3">
<div class="alert alert-info">You are currently <b>LOGGED IN</b>.</div>
<div class="alert alert-danger"><b>Import Online</b> will erase your local save, save it before if you don't want to lose it.<br>
<b>Export Online</b> will erase your online save, you can download it before if you don't want to lose it.</div>
<div class="alert alert-warning"><b>Import Online</b> will <b>replace</b> your local save with your online save, save it before importing if you don't want to lose it.<br>
<b>Export Online</b> will <b>replace</b> your online save, you can download it before exporting if you don't want to lose it.</div>
<div class="row no-gutters input-group">
<div class="col-sm-12 col-md-8 text-center">
<button class="btn btn-primary mr-2 my-2" data-button-protect="importOnline"><i class="fas fa-download"></i> Import Online</button>
@@ -37,5 +37,5 @@ let defaultOptions = {
isLoggedIn: false,
token: "",
version: 2.2,
subVersion: 0
subVersion: 1
};
@@ -785,7 +785,7 @@ class MyMangaDex {
let data = await storageGet(this.manga.mangaDexId);
// If there is no entry for mal link
if (data === undefined) {
this.notification(NOTIFY.INFO, "No MyAnimeList ID in storage", "Searching on the manga page of **" + this.manga.name + "** to find a MyAnimeList id.", this.mmdImage);
this.notification(NOTIFY.INFO, "No MyAnimeList ID", "Searching on the manga page of **" + this.manga.name + "** to find a MyAnimeList id.", this.mmdImage);
} else {
// Get the mal id from the local storage
this.manga.myAnimeListId = data.mal;
@@ -805,8 +805,8 @@ class MyMangaDex {
// Scan the manga page for the mal icon and mal url
let myAnimeListURL = /<a.+href='(.+)'>MyAnimeList<\/a>/.exec(data.body);
// If regex is empty, there is no mal link, can't do anything
if (data === undefined && myAnimeListURL === null) {
this.notification(NOTIFY.ERROR, "No MyAnimeList id found", "You will need to go on the manga page if one is added.\nLast open chapters are still saved.", this.mmdCrossedImage, true);
if (data == undefined || myAnimeListURL == null) {
this.notification(NOTIFY.ERROR, "No MyAnimeList ID", "You will need to go on the manga page if one is added.\nLast open chapters are still saved.", this.mmdCrossedImage, true);
} else {
// If there is a mal link, add it and save it in local storage
this.manga.myAnimeListId = Math.floor(/.+\/(\d+)/.exec(myAnimeListURL[1])[1]);
@@ -971,6 +971,9 @@ class MyMangaDex {
}

chapterStringFromObject(chapter) {
if (typeof chapter != "object") {
return ["Chapter ", chapter].join("");
}
let string = [];
if (chapter.volume > 0) {
string.push("Vol. ", chapter.volume, " ");
@@ -1087,13 +1087,16 @@ class OptionsManager {
data.history[title.md_id] = {
name: title.name,
id: title.md_id,
progress: parseFloat(title.progress),
progress: {
volume: Math.floor(title.progress.volume),
chapter: parseFloat(title.progress.progress)
},
chapter: Math.floor(title.chapter)
};
});
await storageSet(null, data);
// Load options to check for updates
this.options = await loadOptions(); // TODO: Fix missing keys ?
this.options = await loadOptions();
// Update UI
await this.restoreOptions();
this.flashBackground(true);
@@ -1114,7 +1117,8 @@ class OptionsManager {
options: JSON.parse(JSON.stringify(this.options)),
titles: {},
history: {
list: []
list: [],
titles: {}
}
};

@@ -1127,18 +1131,19 @@ class OptionsManager {
// History
if (this.options.updateHistoryPage) {
let history = await storageGet("history");
body.history.list = history.list;
body.history.titles = {};
Object.keys(history).forEach(id => {
if (id != 'list') {
history.titles[id] = {
md_id: id,
name: history[id].name,
progress: history[id].progress,
chapter: history[id].chapter,
};
}
});
if (history) {
body.history.list = history.list;
Object.keys(history).forEach(id => {
if (id != 'list') {
body.history.titles[id] = {
md_id: id,
name: history[id].name,
progress: history[id].progress,
chapter: history[id].chapter,
};
}
});
}
}

// Send the request
@@ -1209,6 +1214,7 @@ class OptionsManager {
this.options.token = "";
// Delete the form too
this.onlineForm.username.value = "";
this.onlineForm.password.value = "";
// Save
this.handleOnlineSuccess(response.body);
this.saveOptions();
@@ -98,6 +98,27 @@ async function loadOptions() {
}
data.subVersion = 5;
}
if (data.version == 2.2) {
// Fix imported history wrong progress
if (data.subVersion < 1) {
let history = await storageGet("history");
if (history) {
Object.keys(history).forEach(md_id => {
if (md_id == 'list') return;
if (typeof history[md_id].progress != 'object') {
history[md_id].progress = {
volume: 0,
chapter: history[md_id].progress
};
}
});
} else {
history = { list: [] };
}
await storageSet("history", history);
}
data.subVersion = 1;
}
await storageSet("options", data);
}

@@ -221,13 +242,14 @@ async function updateLocalStorage(manga, options) {
last: manga.lastMangaDexChapter,
options: {
"saveAllOpened": options.saveAllOpened,
"maxChapterSaved": options.maxChapterSaved,
"updateHistoryPage": options.updateHistoryPage
"maxChapterSaved": options.maxChapterSaved
}
};
if (options.updateHistoryPage &&
manga.name != undefined &&
manga.chapterId != undefined) {
manga.chapterId > 0) {
body.options.updateHistoryPage = true;
body.volume = manga.currentChapter.volume;
body.title_name = manga.name;
body.chapter = manga.chapterId;
}
@@ -262,7 +284,7 @@ async function updateLocalStorage(manga, options) {
SimpleNotification.error({
title: "Couldn't save Online",
image: "https://ramune.nikurasu.org/mymangadex/128b.png",
text: "The Online Service might have a problem, or your credentials has been changed.\nYou have been **logged out*, go to the options to log in again.",
text: "The Online Service might have a problem, or your credentials has been changed.\nYou have been **logged out**, go to the options to log in again.",
buttons: {
value: "Open Options",
type: "message",

0 comments on commit cc22a4d

Please sign in to comment.
You can’t perform that action at this time.