-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathTheSpectrum.js
209 lines (209 loc) · 8.51 KB
/
TheSpectrum.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
205
206
207
208
209
var TheSpectrum = {
mirrorName: "The Spectrum",
canListFullMangas: true,
mirrorIcon: "img/thespectrum.png",
languages: "en",
isMe: function (url) {
return (url.indexOf("thespectrum.net/") != -1 || url.indexOf("mangamonger.com/") != -1);
},
getMangaList: function (search, callback) {
$.ajax({
url: "http://www.thespectrum.net/manga_scans/",
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 = [];
$("span#all a", div).each(function (index) {
if (index > 1) {
res[res.length] = [$(this).text(), "http://www.thespectrum.net" + $(this).attr("href")];
}
});
callback("The Spectrum", res);
}
});
},
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 linka;
$("a", $($("#mainmid .mainbgtop > p", div))).each(function (index) {
if (linka == undefined && $(this).attr("target") != "" && $(this).attr("target") != "_blank" && $(this).attr("href").indexOf("thespectrum.net/") != -1) {
linka = $(this).attr("href");
}
});
$.ajax({
url: linka,
beforeSend: function (xhr) {
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Pragma", "no-cache");
},
success: function (resp) {
var div2 = document.createElement("div");
div2.innerHTML = resp;
var res = [];
$(".viewerLabel .selectchapter option", div2).each(function (index) {
res[res.length] = [$(this).text(), linka + "?ch=" + $(this).val() + "&page=1"];
});
res.reverse();
callback(res, obj);
}
});
}
});
},
getInformationsFromCurrentPage: function (doc, curUrl, callback) {
var currentMangaURL;
var nameManga;
var currentChapter;
var currentChapterURL;
currentMangaURL = "";
$(".viewerLabel", $("#mainGallery .post form[name='pageSelector1']", doc)).each(function (index) {
if (nameManga == undefined && !$(this).hasClass("hidden")) {
nameManga = $(this).text().trim();
}
});
chrome.extension.sendRequest({
action: "getListManga",
mirror: "The Spectrum"
}, function (res) {
var tmpNM = nameManga.replace(/[^a-zA-Z0-9]/g, "");
for (var i = 0; i < res.length; i++) {
if (tmpNM == res[i][0].replace(/[^a-zA-Z0-9]/g, "")) {
currentMangaURL = res[i][1];
nameManga = res[i][0];
break;
}
}
currentChapter = $(".viewerLabel .selectchapter option:selected", doc).text();
chrome.extension.sendRequest({
action: "getListChap",
mirror: "The Spectrum",
mangaUrl: currentMangaURL,
mangaName: nameManga
}, function (res) {
var base = res[0][1];
if (base.indexOf(".html") != -1) {
var pos = base.indexOf(".html");
base = base.substr(0, pos) + ".html";
}
else {
var pos = base.lastIndexOf("/");
base = base.substr(0, pos) + "/";
}
currentChapterURL = base + "?ch=" + $(".viewerLabel .selectchapter option:selected", doc).val() + "&page=1";
callback({
"name": nameManga,
"currentChapter": currentChapter,
"currentMangaURL": currentMangaURL,
"currentChapterURL": currentChapterURL
});
});
});
},
getListImages: function (doc, curUrl) {
var ref = curUrl;
pos = ref.lastIndexOf(".html");
if (pos != -1) {
ref = ref.substr(0, pos) + ".html?ch=" + $(".viewerLabel .selectchapter option:selected", doc).text() + "&page=";
}
else {
pos = ref.lastIndexOf("/");
ref = ref.substr(0, pos) + "/?ch=" + $(".viewerLabel .selectchapter option:selected", doc).text() + "&page=";
}
var res = [];
$(".viewerLabel select.selectpage option", doc).each(function (index) {
res[index] = ref + $(this).val();
});
return res;
},
removeBanners: function (doc, curUrl) {
$("iframe", doc).remove();
},
whereDoIWriteScans: function (doc, curUrl) {
return $(".scansAMR", doc);
},
whereDoIWriteNavigation: function (doc, curUrl) {
return $(".navAMR", doc);
},
isCurrentPageAChapterPage: function (doc, curUrl) {
return (curUrl.search('view.thespectrum.net/series/') > -1)
},
doSomethingBeforeWritingScans: function (doc, curUrl) {
if ($("#midtable", doc).size() > 0) {
$("#midtable", doc).wrap($("<div class='scansAMR'></div>"));
$("#midtable", doc).remove();
$(".scansAMR", doc).before($("<div class='navAMR'></div>"));
$(".scansAMR", doc).after($("<div class='navAMR'></div>"));
$(".navAMR", doc).css("text-align", "center");
}
else {
$("body > table", doc).css("display", "none");
$("body > table", doc).after($("<div class='navAMR'></div>"));
$("body > table", doc).next().after($("<div class='scansAMR'></div>"));
$("body > table", doc).next().next().after($("<div class='navAMR'></div>"));
$(".navAMR", doc).css("text-align", "center");
}
},
nextChapterUrl: function (select, doc, curUrl) {
if ($(select).children("option:selected").next().size() != 0) {
var chap = $(select).children("option:selected").next().val();
return chap;
}
return null;
},
previousChapterUrl: function (select, doc, curUrl) {
if ($(select).children("option:selected").prev().size() != 0) {
var chap = $(select).children("option:selected").prev().val();
return chap;
}
return null;
},
getImageFromPageAndWrite: function (urlImg, image, doc, curUrl) {
$.ajax({
url: urlImg,
success: function (objResponse) {
var div = document.createElement("div");
div.innerHTML = objResponse;
var src;
if (curUrl.indexOf("view.thespectrum.net") != -1) {
src = $(".imgContainer img#mainimage", div).attr("src");
}
else {
src = "http://view.mangamonger.com" + $(".imgContainer img#mainimage", div).attr("src");
}
$(image).attr("src", src);
}
});
},
isImageInOneCol: function (img, doc, curUrl) {
return false;
},
getMangaSelectFromPage: function (doc, curUrl) {
$(".viewerLabel .selectchapter option", doc).each(function (index) {
var base = $("#mainGallery .post h1 > a", doc).attr("href");
if (base == undefined || base.length == 0) {
base = $("#head #title a", doc).attr("href");
}
$(this).val(base + "?ch=" + $(this).val() + "&page=1");
});
return $(".viewerLabel .selectchapter", doc);
},
doAfterMangaLoaded: function (doc, curUrl) {
$("body > div:empty", doc).remove();
},
}
// Call registerMangaObject to be known by includer
if (typeof registerMangaObject == 'function') {
registerMangaObject("The Spectrum", TheSpectrum);
}