-
Notifications
You must be signed in to change notification settings - Fork 16
/
AnimeStory.js
204 lines (204 loc) · 9.53 KB
/
AnimeStory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*/////////////////////////////////////////////////////////////////////////////
// //
// All Mangas Reader : Follow updates of your favorite mangas sites. //
// Copyright (c) 2011 Pierre-Louis DUHOUX (pl.duhoux at gmail d0t com) //
// //
/////////////////////////////////////////////////////////////////////////////*/
/********************************************************************************************************
IMPORTANT NOTE : methods which are running in the DOM of the page could directly use this DOM.
However, if you want to test the mirror with the lab, you must use the two arguments (doc and curUrl)
of these methods to avoid using window.location.href (replaced by curUrl) and manipulate the DOM within
the object doc (example, replace $("select") by $("select", doc) in jQuery).
********************************************************************************************************/
var AnimeStory = {
//Name of the mirror
mirrorName : "AnimeStory",
//True if the mirror can list all of its mangas.
canListFullMangas : true,
//Extension internal link to the icon of the mirror.
mirrorIcon : "img/animestory.png",
//Languages of scans for the mirror
languages : "fr",
//Return true if the url corresponds to the mirror
isMe : function(url) {
return ((url.indexOf("anime-story.com") != -1) || (url.indexOf("instantmanga.com") != -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: "http://www.anime-story.com/mangas/",
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 = [];
$("#mangalist li a", div).each(function(index) {
var txt = "";
$(this).contents().each(
function(index){if (index == 0) txt += $(this).text();
});
res[res.length] = [txt.trim(), "http://www.anime-story.com/" + $(this).attr("href")];
});
callback("AnimeStory", 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" );
div.innerHTML = objResponse;
var res = [];
$(".listchapseries li", div).each(function(index) {
var txt = $(".chapter_series", $(this)).text();
txt = txt.trim().replace(mangaName, "");
res[res.length] = [txt, $("div:first a:last", $(this)).attr("href")];
});
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 = $("#serie option:selected", doc).text();
//currentMangaURL = $("#serie option:selected", doc).val().replace("http://www.anime-story.com/", "http://www.anime-story.com/mangas/");
currentMangaURL = 'http://www.anime-story.com/mangas/' + $('#serie option:selected', doc).val();
currentChapter = $("#pagenumber option:selected", doc).text();
currentChapterURL = $("#pagenumber option:selected", doc).val();
/*console.log(" name : " + name +
" currentChapter : " + currentChapter +
" currentMangaURL : " + currentMangaURL +
" currentChapterURL : " + currentChapterURL);*/
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 = [];
$("#page:first select option", doc).each(
function(index){
res[index] = $(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.
$("#ad").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 $("#scansAMR", 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 $("#nav", doc).add($("#navAMR", doc));
},
//Return true if the current page is a page containing scan.
isCurrentPageAChapterPage : function(doc, curUrl) {
return ($("#auto img", 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.
$("#nav", doc).next().remove();
$("#nav", doc).after($("<div id='scansAMR'></div>"));
$("#nav", doc).empty();
$("#nav", doc).css("text-align", "center");
$("#scansAMR", doc).after($("<div id='navAMR'></div>"));
$("#navAMR", doc).css("text-align", "center");
},
//This method is called to fill the next button's url in the manga site navigation bar
//The select containing the mangas list next to the button is passed in argument
nextChapterUrl : function(select, doc, curUrl) {
//This function runs in the DOM of the current consulted page.
if ($(select).children("option:selected").prev().size() != 0) {
return $(select).children("option:selected").prev().val();
}
return null;
},
//This method is called to fill the previous button's url in the manga site navigation bar
//The select containing the mangas list next to the button is passed in argument
previousChapterUrl : function(select, doc, curUrl) {
//This function runs in the DOM of the current consulted page.
if ($(select).children("option:selected").next().size() != 0) {
return $(select).children("option:selected").next().val();
}
return null;
},
//Write the image from the the url returned by the getListImages() function.
//The function getListImages can return an url which is not the source of the
//image. The src of the image is set by this function.
//If getListImages function returns the src of the image, just do $( image ).attr( "src", urlImg );
getImageFromPageAndWrite : function(urlImg, image, doc, curUrl) {
//This function runs in the DOM of the current consulted page.
$.ajax(
{
url: 'http://www.instantmanga.com/' + urlImg,
success: function( objResponse ){
var div = document.createElement( "div" );
div.innerHTML = objResponse;
var src = $("#auto a[rel=next] img", div).attr("src");
$( image ).attr( "src", src);
}
});
},
//If it is possible to know if an image is a credit page or something which
//must not be displayed as a book, just return true and the image will stand alone
//img is the DOM object of the image
isImageInOneCol : function(img, doc, curUrl) {
//This function runs in the DOM of the current consulted page.
return false;
},
//This function can return a preexisting select from the page to fill the
//chapter select of the navigation bar. It avoids to load the chapters
getMangaSelectFromPage : function(doc, curUrl) {
//This function runs in the DOM of the current consulted page.
return $("#pagenumber:first", doc);
},
//This function is called when the manga is full loaded. Just do what you want here...
doAfterMangaLoaded : function(doc, curUrl) {
//This function runs in the DOM of the current consulted page.
$("body > div:empty", doc).remove();
}
}
// Call registerMangaObject to be known by includer
if (typeof registerMangaObject == 'function') {
registerMangaObject("AnimeStory", AnimeStory);
}