Commit 8490cd40 authored by Duhoux Pierre-Louis's avatar Duhoux Pierre-Louis

Fix #43 Manga Here after huge update (similar to FanFox)

parent f3b7082b
Pipeline #43896232 passed with stages
in 1 minute and 33 seconds
if (typeof registerMangaObject === 'function') {
registerMangaObject({
registerMangaObject({
mirrorName: "Manga Here",
canListFullMangas: false,
mirrorIcon: "mangahere.png",
......@@ -9,76 +9,120 @@ if (typeof registerMangaObject === 'function') {
chapter_url: /\/manga\/.*\/.+\/.*/g,
getMangaList: async function (search) {
let doc = await amr.loadPage("https://www.mangahere.cc/search.php?name=" + search, { nocache: true, preventimages: true })
let doc = await amr.loadPage("https://www.mangahere.cc/search?title=" + search, { nocache: true, preventimages: true })
let res = []
$(".result_search dl dt a:first-child", doc).each(function (index) {
res[res.length] = [$(this).attr("rel").trim(), "https:" + $(this).attr("href")];
$(".line-list ul .manga-list-4-item-title > a", doc).each(function (index) {
res[res.length] = [$(this).text().trim(), "https://www.mangahere.cc" + $(this).attr("href")];
});
return res
},
getListChaps: async function (urlManga) {
let doc = await amr.loadPage(urlManga, { nocache: true, preventimages: true })
if ($("#checkAdult", doc).length > 0) {
amr.setCookie({ // set the cookie on fanfox domain
name: "isAdult",
value: "1",
path: "/",
url: urlManga,
domain: "www.mangahere.cc",
expirationDate: new Date().getTime() + (24 * 60 * 60 * 1000)
})
doc = await amr.loadPage(urlManga, { nocache: true, preventimages: true })
}
let res = [];
$(".detail_list ul li span.left a", doc).each(function (index) {
res[res.length] = [$(this).text().trim(), "https:" + $(this).attr("href")];
$(".detail-main-list a", doc).each(function () {
let url = "https://www.mangahere.cc" + $(this).attr("href")
url = url.substr(0, url.lastIndexOf("/") + 1);
res.push([$(".title3", $(this)).text(), url]);
});
return res
},
getInformationsFromCurrentPage: async function (doc, curUrl) {
var name;
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();
}
currentChapterURL = "https:" + $($(".readpage_top .title a", doc)[0]).attr("href");
currentMangaURL = "https:" + $($(".readpage_top .title a", doc)[1]).attr("href");
let mga = $(".reader-header-title-1 a", doc)
return {
"name": name,
"currentMangaURL": currentMangaURL,
"currentChapterURL": currentChapterURL
}
"name": mga.text(),
"currentMangaURL": "https://www.mangahere.cc" + mga.attr("href"),
"currentChapterURL": curUrl.substr(0, curUrl.lastIndexOf("/") + 1)
};
},
getListImages: async function (doc, curUrl) {
var res = [];
$("select.wid60:first option", doc).each(function (index) {
if (!isNaN(parseFloat($(this).text()))) res[res.length] = "https:" + $(this).val();
});
let lastpage = amr.getVariable("imagecount", doc),
curl = curUrl.substr(0, curUrl.lastIndexOf("/") + 1),
res = []
for (let i = 1; i <= lastpage; i++) {
res.push(curl + i + ".html")
}
return res;
},
getImageFromPageAndWrite: async function (urlImg, image) {
// loads the page containing the current scan
let doc = await amr.loadPage(urlImg)
var src = $("#image", doc).attr("src");
$(image).attr("src", src);
var mkey = '';
if ($("#dm5_key", doc).length > 0) {
mkey = $("#dm5_key", doc).val();
}
let curl = urlImg.substr(0, urlImg.lastIndexOf("/") + 1),
cid = amr.getVariable("chapterid", doc),
chapfunurl = curl + "chapterfun.ashx", // url to retrieve scan url
curpage = amr.getVariable("imagepage", doc)
let params = { // Build parameters for the request
cid: cid,
page: curpage,
key: mkey
}
// get scan url (this function seems to work only within DM5, perhaps a control on Referer)
let data = await amr.loadJson(
chapfunurl,
{
data: params,
nocontenttype: true,
headers: { "X-Requested-With": "XMLHttpRequest" },
referer: urlImg
}
)
// the retrieved data is packed through an obfuscator
// dm5 is unpacking the images url through an eval, we can't do that in AMR due to CSP
// we do it manually (below is the unpack function shipped with the data to decode)
let unpack = function (p, a, c, k, e, d) { e = function (c) { return (c < a ? "" : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) d[e(c)] = k[c] || e(c); k = [function (e) { return d[e] }]; e = function () { return '\\w+' }; c = 1; }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p; }
// regexp to parse the arguments to pass to the unpack function, just parse the 4 first arguments
let regexpargs = /'(([^\\']|\\')*)',([0-9]+),([0-9]+),'(([^\\']|\\')*)'/g
let match = regexpargs.exec(data)
if (match) {
args = [match[1], match[3], match[4], match[5].split("|"), 0, {}]
let sc = unpack(...args) // call the unpack function
sc = sc.replace(/\\'/g, "'") // unquote the result
// the result is another js function containing the data, we mimic here what it does
// retrieve the variables
let cid = amr.getVariableFromScript("cid", sc),
key = amr.getVariableFromScript("key", sc),
pix = amr.getVariableFromScript("pix", sc),
pvalue = amr.getVariableFromScript("pvalue", sc) // array of scan urls (contains current one and next one)
pvalue = pvalue.map(img => pix + img + '?cid=' + cid + '&key=' + key) // mimic the returned function which rebuilds the url depending on its parts
$(image).attr("src", pvalue[0]); // set the image src
} else {
$(image).attr("src", "error");
}
},
whereDoIWriteScans: function (doc, curUrl) {
return $(".scanAMR", doc);
return $(".amr-container", doc);
},
isCurrentPageAChapterPage: function (doc, curUrl) {
return ($("#image", doc).length > 0);
return $(".reader-main-img", doc).length > 0
},
doSomethingBeforeWritingScans: function (doc, curUrl) {
$("#viewer", doc).empty().append($("<div class='amrcontainer'></div>"));
$("#viewer", doc).css({
"margin": "0",
"text-align": "center",
"width": "100%"
});
$(".go_page.clearfix", doc).empty();
$("<div class='scanAMR widepage'></div>").appendTo($(".amrcontainer", doc));
while (!$(".reader-page .ad-reader-con:first", doc).next().is(".ad-reader-con")) {
$(".reader-page .ad-reader-con:first", doc).next().remove()
}
$(".reader-page .ad-reader-con:first", doc).after($("<div class='amr-container'></div>"))
},
doAfterMangaLoaded: function (doc, curUrl) {
$("body > div:empty", doc).remove();
var script = doc.createElement('script');
script.innerText = "Hotkeys.hotkeys.clear();";
doc.body.appendChild(script);
}
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment