Commit 5786b4a1 authored by Duhoux Pierre-Louis's avatar Duhoux Pierre-Louis

Fix MangaFox changed their layout and way to load scans

The way to load scans is really close to DM5 (even DM5 references in the source code)
parent 797455fe
Pipeline #37420952 passed with stages
in 1 minute and 37 seconds
......@@ -8,17 +8,16 @@ if (typeof registerMangaObject === 'function') {
home: "http://fanfox.net/",
getMangaList: async function (search) {
var urlManga = "http://fanfox.net/search.php?name=" + search +
"&advopts=1";
var urlManga = "http://fanfox.net/search?name=" + search;
let doc = await amr.loadPage(urlManga, { nocache: true, preventimages: true })
if ($(doc).text().indexOf("No Manga Series") !== -1) {
return []
} else {
var res = []
$("#mangalist .manga_text .title", doc).each(function (index, a) {
$(".manga-list-4-list li p.manga-list-4-item-title a", doc).each(function (index, a) {
res[index] = [
$(a).html(),
"http:" + $(a).attr("href")
$(a).text(),
"http://fanfox.net" + $(a).attr("href")
];
});
return res;
......@@ -26,88 +25,111 @@ if (typeof registerMangaObject === 'function') {
},
getListChaps: async function (urlManga) {
let doc = await amr.loadPage(urlManga + "?no_warning=1", { nocache: true, preventimages: true })
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: "fanfox.net",
expirationDate: new Date().getTime() + (24*60*60*1000)
})
doc = await amr.loadPage(urlManga, { nocache: true, preventimages: true })
}
let res = [];
var mangaName = $('#title h2', doc).text().substr(5, $('#title h2', doc).text().length - 18);
$("ul.chlist h3, ul.chlist h4", doc).each(function (index) {
if ($('a', $(this)).attr("href").indexOf("/manga/") !== -1) {
var vol = $(this).parents('ul.chlist').prev('div.slide').children('h3').contents(':not(span)').text().trim().substr(7);
var tit = 'Vol ' + vol + ' Ch ' + $('a', $(this)).text().substr(mangaName.length + 1) + ': ' + $('span.title', $(this)).text();
var url = $('a', $(this)).attr("href");
var curChapURL = url.substr(0, url.lastIndexOf("/") + 1);
if (curChapURL.substr(curChapURL.length - 2, 2) === "//") {
curChapURL = curChapURL.substr(0, curChapURL.length - 1);
}
res[res.length] = [tit.trim(), "http:" + curChapURL];
}
$(".detail-main-list a", doc).each(function () {
let url = "http://fanfox.net" + $(this).attr("href")
url = url.substr(0, url.lastIndexOf("/") + 1);
res.push([$(".title1", $(this)).text(), url]);
});
return res
},
getInformationsFromCurrentPage: async function (doc, curUrl) {
var str = $('#series > strong a', doc).text(); // dom lookups are expensive!
var name = $('#related > h3 a', doc).text() || str.substring(0, str.length - 6); //falls through #related, into #series
var url = curUrl;
var posSl5 = 0;
var i;
for (i = 0; i < 5; i += 1) {
posSl5 = url.indexOf("/", posSl5 + 1);
}
var curChapURL = url.substr(0, url.lastIndexOf("/") + 1);
if (curChapURL.substr(curChapURL.length - 2, 2) === "//") {
curChapURL = curChapURL.substr(0, curChapURL.length - 1);
}
let mga = $(".reader-header-title-1 a", doc)
return {
"name": name,
"currentMangaURL": url.substr(0, posSl5 + 1),
"currentChapterURL": curChapURL
"name": mga.text(),
"currentMangaURL": "http://fanfox.net" + mga.attr("href"),
"currentChapterURL": curUrl.substr(0, curUrl.lastIndexOf("/") + 1)
};
},
getListImages: async function (doc, curUrl) {
var res = [];
$('#top_bar select.m option', doc).each(function () {
if (this.value > 0) {
res.push(curUrl.substr(0, curUrl.lastIndexOf("/") + 1) + this.value + '.html');
}
});
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)
let 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 $("#viewer", doc);
return $(".amr-container", doc);
},
isCurrentPageAChapterPage: function (doc, curUrl) {
if ($("#viewer", doc) !== null) {
return ($("#viewer", doc).length !== 0);
}
return false;
return $(".reader-main-img", doc).length > 0
},
doSomethingBeforeWritingScans: function (doc, curUrl) {
$('#viewer', doc).css({
'width': 'auto',
'margin': 'auto',
'background-color': 'black'
});
$("#image", doc).remove();
$("#tool", doc).next().remove();
$(".widepage.page", doc).remove();
$('.fb_iframe_widget', doc).remove();
$(".read_img", doc).css("background-image", "none");
if (typeof doc.createElement === 'function') {
var script = doc.createElement('script');
script.innerText = "$(document).unbind('keydown');";
doc.body.appendChild(script);
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();
}
})
}
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