var MangaHere = {
//Name of the mirror
mirrorName: "Manga Here",
//True if the mirror can list all of its mangas.
canListFullMangas: false,
//Extension internal link to the icon of the mirror.
mirrorIcon: "img/mangahere.png",
//Languages of scans for the mirror
languages: "en",
//Return true if the url corresponds to the mirror
isMe: function (url) {
return (url.indexOf("mangahere.cc/") != -1);
},
//Return the list of all or part of all mangas from the mirror
//The search parameter is filled if canListFullMangas is false
//This list must be an Array of [["manga name", "url"], ...]
//This function must call callback("Mirror name", [returned list]);
getMangaList: function (search, callback) {
$.ajax({
url: "https://www.mangahere.cc/search.php?name=" + search,
beforeSend: function (xhr) {
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Pragma", "no-cache");
},
success: function (objResponse) {
var div = document.createElement("div");
div.innerHTML = objResponse;
var res = [];
$(".result_search dl dt a:first-child", div).each(function (index) {
res[res.length] = [$(this).text().trim(), this.href];
});
callback("Manga Here", res);
}
});
},
//Find the list of all chapters of the manga represented by the urlManga parameter
//This list must be an Array of [["chapter name", "url"], ...]
//This list must be sorted descending. The first element must be the most recent.
//This function MUST call callback([list of chapters], obj);
getListChaps: function (urlManga, mangaName, obj, callback) {
$.ajax({
url: urlManga,
beforeSend: function (xhr) {
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Pragma", "no-cache");
},
success: function (objResponse) {
var div = document.createElement("div");
objResponse = objResponse.replace(/]*>/ig, ''); //avoid loading cover image
div.innerHTML = objResponse;
var res = [];
$(".detail_list ul li span.left a", div).each(function (index) {
url = this.href.replace("chrome-extension", "http")
res[res.length] = [$(this).text().trim(), url];
});
callback(res, obj);
}
});
},
//This method must return (throught callback method) an object like :
//{"name" : Name of current manga,
// "currentChapter": Name of thee current chapter (one of the chapters returned by getListChaps),
// "currentMangaURL": Url to access current manga,
// "currentChapterURL": Url to access current chapter}
getInformationsFromCurrentPage: function (doc, curUrl, callback) {
//This function runs in the DOM of the current consulted page.
var name;
var currentChapter;
var currentMangaURL;
var currentChapterURL;
name = $($(".readpage_top .title a", doc)[1]).text().trim();
if (name.length >= 5 && name.substr(name.length - 5, 5) == "Manga") {
name = name.substr(0, name.length - 5).trim();
}
currentChapter = $($(".readpage_top .title a", doc)[0]).text();
currentChapterURL = $(".readpage_top .title a", doc)[0].href;
console.log(currentChapterURL);
currentMangaURL = $(".readpage_top .title a", doc)[1].href;
callback({
"name": name,
"currentChapter": currentChapter,
"currentMangaURL": currentMangaURL,
"currentChapterURL": currentChapterURL
});
},
//Returns the list of the urls of the images of the full chapter
//This function can return urls which are not the source of the
//images. The src of the image is set by the getImageFromPageAndWrite() function.
getListImages: function (doc, curUrl) {
//This function runs in the DOM of the current consulted page.
var res = [];
$("select.wid60:first option", doc).each(function (index) {
res[res.length] = $(this).val();
});
return res;
},
//Remove the banners from the current page
removeBanners: function (doc, curUrl) {
//This function runs in the DOM of the current consulted page.
$(".inner_banner", doc).remove();
$("#link_heading_banner", doc).remove();
$(".readpage_top .title", doc).next().remove();
},
//This method returns the place to write the full chapter in the document
//The returned element will be totally emptied.
whereDoIWriteScans: function (doc, curUrl) {
//This function runs in the DOM of the current consulted page.
return $(".scanAMR", doc);
},
//This method returns places to write the navigation bar in the document
//The returned elements won't be emptied.
whereDoIWriteNavigation: function (doc, curUrl) {
//This function runs in the DOM of the current consulted page.
return $(".navAMR", doc);
},
//Return true if the current page is a page containing scan.
isCurrentPageAChapterPage: function (doc, curUrl) {
return ($("#image", doc).size() > 0);
},
//This method is called before displaying full chapters in the page
doSomethingBeforeWritingScans: function (doc, curUrl) {
//This function runs in the DOM of the current consulted page.
$("#viewer", doc).empty().append($("