-
Notifications
You must be signed in to change notification settings - Fork 16
/
MangaTurk.js
199 lines (199 loc) · 9.46 KB
/
MangaTurk.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
/*/////////////////////////////////////////////////////////////////////////////
// //
// 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 MangaTurk = {
//Name of the mirror
mirrorName : "MangaTurk",
//True if the mirror can list all of its mangas.
canListFullMangas : true,
//Extension internal link to the icon of the mirror.
mirrorIcon : "img/mangaturk.png",
//Languages of scans for the mirror
languages : "tr",
//Return true if the url corresponds to the mirror
isMe : function(url) {
return (url.indexOf("turkcraft.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.turkcraft.com/",
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 = [];
$("select[name='manga'] option", div).each(function(index) {
if (index > 0) {
res[res.length] = [$(this).text(), "http://www.turkcraft.com/" + $(this).val()];
}
});
callback("MangaTurk", 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 = [];
$("select[name='chapter']:first option", div).each(function(index) {
res[res.length] = [$(this).text(), urlManga + "/" + $(this).val()];
});
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 = $("select[name='manga']:first option:selected", doc).text();
currentMangaURL = "http://www.turkcraft.com/" + $("select[name='manga']:first option:selected", doc).val();
currentChapter = $("select[name='chapter']:first option:selected", doc).text();
currentChapterURL = currentMangaURL + "/" + $("select[name='chapter']:first 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 = [];
var mg = "http://www.turkcraft.com/" + $("select[name='manga']:first option:selected", doc).val();
var chap = mg + "/" + $("select[name='chapter']:first option:selected", doc).val();
$("select[name='page']:first option", doc).each(function(index) {
res[res.length] = chap + "/" + $(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.
$("iframe", doc).parents("ins").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 $(".pager", doc);
},
//Return true if the current page is a page containing scan.
isCurrentPageAChapterPage : function(doc, curUrl) {
return ($("img.picture", 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.
$(".pager", doc).empty();
$("img.picture", doc).closest("td").html("<div class='scansAMR'></div>");
},
//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: urlImg,
success: function( objResponse ){
var div = document.createElement( "div" );
div.innerHTML = objResponse;
var src = "http://www.turkcraft.com/" + $("img.picture", 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.
var res = [];
var mg = "http://www.turkcraft.com/" + $("select[name='manga']:first option:selected", doc).val();
$("select[name='chapter']:first option", doc).each(function(index) {
$(this).val(mg + "/" + $(this).val());
});
return $("select[name='chapter']: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("MangaTurk", MangaTurk);
}