Fix "Open in WebView" not working. (#2638)

Fix "Open in WebView" not working at MangasProject
This commit is contained in:
Alessandro Jean 2020-04-10 22:22:58 -03:00 committed by GitHub
parent 57efc954a9
commit 4f8fe13829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 17 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: mangásPROJECT' appName = 'Tachiyomi: mangásPROJECT'
pkgNameSuffix = 'pt.mangasproject' pkgNameSuffix = 'pt.mangasproject'
extClass = '.MangasProjectFactory' extClass = '.MangasProjectFactory'
extVersionCode = 9 extVersionCode = 10
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -45,10 +45,15 @@ abstract class MangasProject(
override fun headersBuilder(): Headers.Builder = Headers.Builder() override fun headersBuilder(): Headers.Builder = Headers.Builder()
.add("User-Agent", USER_AGENT) .add("User-Agent", USER_AGENT)
.add("Referer", baseUrl) .add("Referer", baseUrl)
// Use internal headers to allow "Open in WebView" to work.
private fun sourceHeadersBuilder(): Headers.Builder = headersBuilder()
.add("X-Requested-With", "XMLHttpRequest") .add("X-Requested-With", "XMLHttpRequest")
private val sourceHeaders: Headers by lazy { sourceHeadersBuilder().build() }
override fun popularMangaRequest(page: Int): Request { override fun popularMangaRequest(page: Int): Request {
return GET("$baseUrl/home/most_read?page=$page", headers) return GET("$baseUrl/home/most_read?page=$page", sourceHeaders)
} }
override fun popularMangaParse(response: Response): MangasPage { override fun popularMangaParse(response: Response): MangasPage {
@ -69,7 +74,7 @@ abstract class MangasProject(
} }
override fun latestUpdatesRequest(page: Int): Request { override fun latestUpdatesRequest(page: Int): Request {
return GET("$baseUrl/home/releases?page=$page", headers) return GET("$baseUrl/home/releases?page=$page", sourceHeaders)
} }
override fun latestUpdatesParse(response: Response): MangasPage { override fun latestUpdatesParse(response: Response): MangasPage {
@ -94,7 +99,7 @@ abstract class MangasProject(
.add("search", query) .add("search", query)
.build() .build()
return POST("$baseUrl/lib/search/series.json", headers, form) return POST("$baseUrl/lib/search/series.json", sourceHeaders, form)
} }
override fun searchMangaParse(response: Response): MangasPage { override fun searchMangaParse(response: Response): MangasPage {
@ -118,14 +123,6 @@ abstract class MangasProject(
artist = obj["artist"].string artist = obj["artist"].string
} }
override fun mangaDetailsRequest(manga: SManga): Request {
val newHeaders = headersBuilder()
.removeAll("X-Requested-With")
.build()
return GET(baseUrl + manga.url, newHeaders)
}
override fun mangaDetailsParse(response: Response): SManga { override fun mangaDetailsParse(response: Response): SManga {
val document = response.asJsoup() val document = response.asJsoup()
@ -180,7 +177,7 @@ abstract class MangasProject(
} }
private fun chapterListRequestPaginated(mangaUrl: String, id: String, page: Int): Request { private fun chapterListRequestPaginated(mangaUrl: String, id: String, page: Int): Request {
val newHeaders = headersBuilder() val newHeaders = sourceHeadersBuilder()
.set("Referer", baseUrl + mangaUrl) .set("Referer", baseUrl + mangaUrl)
.build() .build()
@ -241,14 +238,13 @@ abstract class MangasProject(
override fun pageListRequest(chapter: SChapter): Request { override fun pageListRequest(chapter: SChapter): Request {
val newHeaders = headersBuilder() val newHeaders = headersBuilder()
.set("Referer", baseUrl + chapter.url) .set("Referer", baseUrl + chapter.url)
.removeAll("X-Requested-With")
.build() .build()
return GET(baseUrl + chapter.url, newHeaders) return GET(baseUrl + chapter.url, newHeaders)
} }
private fun pageListApiRequest(chapterUrl: String, token: String): Request { private fun pageListApiRequest(chapterUrl: String, token: String): Request {
val newHeaders = headersBuilder() val newHeaders = sourceHeadersBuilder()
.set("Referer", chapterUrl) .set("Referer", chapterUrl)
.build() .build()
@ -267,7 +263,7 @@ abstract class MangasProject(
return result return result
val document = result.asJsoup() val document = result.asJsoup()
val token = document.select("script[src*=\"reader.\"]") val token = document.select("script[src*=\"reader.\"]").first()
?.let { ?.let {
HttpUrl.parse(it.attr("abs:src"))!! HttpUrl.parse(it.attr("abs:src"))!!
.queryParameter("token") .queryParameter("token")
@ -292,7 +288,6 @@ abstract class MangasProject(
override fun imageRequest(page: Page): Request { override fun imageRequest(page: Page): Request {
val newHeaders = headersBuilder() val newHeaders = headersBuilder()
.set("Referer", page.url) .set("Referer", page.url)
.removeAll("X-Requested-With")
.build() .build()
return GET(page.imageUrl!!, newHeaders) return GET(page.imageUrl!!, newHeaders)