From bcf57d6f7374445b599a155af2e32d987825fdde Mon Sep 17 00:00:00 2001 From: are-are-are <62763969+dejavui@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:16:56 +0700 Subject: [PATCH] Add domain switcher XXManhwa, TruyenVn, SayHentai & Fix author TruyenGG (#6157) * Add url change feature XXManhwa, TruyenVn, SayHentai * Fix author Truyengg * Fix truyenvn --- src/vi/sayhentai/build.gradle | 2 +- .../extension/vi/sayhentai/SayHentai.kt | 67 +++++++++++++++++-- src/vi/truyengg/build.gradle | 2 +- .../extension/vi/truyengg/TruyenGG.kt | 2 +- src/vi/truyenvn/build.gradle | 2 +- .../extension/vi/truyenvn/TruyenVN.kt | 65 ++++++++++++++++-- src/vi/xxmanhwa/build.gradle | 2 +- .../extension/vi/xxmanhwa/XxManhwa.kt | 39 ++++++++++- 8 files changed, 162 insertions(+), 19 deletions(-) diff --git a/src/vi/sayhentai/build.gradle b/src/vi/sayhentai/build.gradle index 8da92690b..df3da260d 100644 --- a/src/vi/sayhentai/build.gradle +++ b/src/vi/sayhentai/build.gradle @@ -3,7 +3,7 @@ ext { extClass = ".SayHentai" themePkg = "manhwaz" baseUrl = "https://sayhentai.art" - overrideVersionCode = 8 + overrideVersionCode = 9 isNsfw = true } diff --git a/src/vi/sayhentai/src/eu/kanade/tachiyomi/extension/vi/sayhentai/SayHentai.kt b/src/vi/sayhentai/src/eu/kanade/tachiyomi/extension/vi/sayhentai/SayHentai.kt index ad700c931..2c3420d43 100644 --- a/src/vi/sayhentai/src/eu/kanade/tachiyomi/extension/vi/sayhentai/SayHentai.kt +++ b/src/vi/sayhentai/src/eu/kanade/tachiyomi/extension/vi/sayhentai/SayHentai.kt @@ -1,13 +1,66 @@ package eu.kanade.tachiyomi.extension.vi.sayhentai +import android.app.Application +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.multisrc.manhwaz.ManhwaZ +import eu.kanade.tachiyomi.source.ConfigurableSource +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get -class SayHentai : ManhwaZ( - "SayHentai", - "https://sayhentai.art", - "vi", - mangaDetailsAuthorHeading = "Tác giả", - mangaDetailsStatusHeading = "Trạng thái", -) { +class SayHentai : + ManhwaZ( + "SayHentai", + "https://sayhentai.art", + "vi", + mangaDetailsAuthorHeading = "Tác giả", + mangaDetailsStatusHeading = "Trạng thái", + ), + ConfigurableSource { override fun popularMangaSelector() = "#slide-top > .item:contains(a)" + + private val preferences: SharedPreferences = + Injekt.get().getSharedPreferences("source_$id", 0x0000) + + init { + preferences.getString(DEFAULT_BASE_URL_PREF, null).let { prefDefaultBaseUrl -> + if (prefDefaultBaseUrl != super.baseUrl) { + preferences.edit() + .putString(BASE_URL_PREF, super.baseUrl) + .putString(DEFAULT_BASE_URL_PREF, super.baseUrl) + .apply() + } + } + } + + override val baseUrl by lazy { getPrefBaseUrl() } + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + val baseUrlPref = androidx.preference.EditTextPreference(screen.context).apply { + key = BASE_URL_PREF + title = BASE_URL_PREF_TITLE + summary = BASE_URL_PREF_SUMMARY + setDefaultValue(super.baseUrl) + dialogTitle = BASE_URL_PREF_TITLE + dialogMessage = "Default: ${super.baseUrl}" + + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, RESTART_APP, Toast.LENGTH_LONG).show() + true + } + } + screen.addPreference(baseUrlPref) + } + + private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, super.baseUrl)!! + + companion object { + private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl" + private const val RESTART_APP = "Khởi chạy lại ứng dụng để áp dụng thay đổi." + private const val BASE_URL_PREF_TITLE = "Ghi đè URL cơ sở" + private const val BASE_URL_PREF = "overrideBaseUrl" + private const val BASE_URL_PREF_SUMMARY = + "Dành cho sử dụng tạm thời, cập nhật tiện ích sẽ xóa cài đặt." + } } diff --git a/src/vi/truyengg/build.gradle b/src/vi/truyengg/build.gradle index 3f917fb1a..6dc5c9e19 100644 --- a/src/vi/truyengg/build.gradle +++ b/src/vi/truyengg/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'TruyenGG' extClass = '.TruyenGG' - extVersionCode = 1 + extVersionCode = 2 } apply from: "$rootDir/common.gradle" diff --git a/src/vi/truyengg/src/eu/kanade/tachiyomi/extension/vi/truyengg/TruyenGG.kt b/src/vi/truyengg/src/eu/kanade/tachiyomi/extension/vi/truyengg/TruyenGG.kt index 30f6f2906..ed4e82645 100644 --- a/src/vi/truyengg/src/eu/kanade/tachiyomi/extension/vi/truyengg/TruyenGG.kt +++ b/src/vi/truyengg/src/eu/kanade/tachiyomi/extension/vi/truyengg/TruyenGG.kt @@ -81,7 +81,7 @@ class TruyenGG : ParsedHttpSource(), ConfigurableSource { override fun mangaDetailsParse(document: Document): SManga = SManga.create().apply { title = document.select("h1[itemprop=name]").text() - author = document.select("p:contains(Tác Giả) + p").joinToString { it.text() } + author = document.selectFirst("p:contains(Tác Giả) + p")?.text() genre = document.select("a.clblue").joinToString { it.text() } description = document.select("div.story-detail-info").text().trim() thumbnail_url = document.selectFirst(".thumbblock img")!!.attr("abs:src") diff --git a/src/vi/truyenvn/build.gradle b/src/vi/truyenvn/build.gradle index 6d1328cbd..8b2c5a755 100644 --- a/src/vi/truyenvn/build.gradle +++ b/src/vi/truyenvn/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.TruyenVN' themePkg = 'madara' baseUrl = 'https://truyenvn.vin' - overrideVersionCode = 7 + overrideVersionCode = 8 isNsfw = true } diff --git a/src/vi/truyenvn/src/eu/kanade/tachiyomi/extension/vi/truyenvn/TruyenVN.kt b/src/vi/truyenvn/src/eu/kanade/tachiyomi/extension/vi/truyenvn/TruyenVN.kt index d221d7902..f74aad707 100644 --- a/src/vi/truyenvn/src/eu/kanade/tachiyomi/extension/vi/truyenvn/TruyenVN.kt +++ b/src/vi/truyenvn/src/eu/kanade/tachiyomi/extension/vi/truyenvn/TruyenVN.kt @@ -1,17 +1,70 @@ package eu.kanade.tachiyomi.extension.vi.truyenvn +import android.app.Application +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.multisrc.madara.Madara +import eu.kanade.tachiyomi.source.ConfigurableSource +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import java.text.SimpleDateFormat import java.util.Locale -class TruyenVN : Madara( - "TruyenVN", - "https://truyenvn.vin", - "vi", - dateFormat = SimpleDateFormat("dd/MM/yyyy", Locale.ROOT), -) { +class TruyenVN : + Madara( + "TruyenVN", + "https://truyenvn.vin", + "vi", + dateFormat = SimpleDateFormat("dd/MM/yyyy", Locale.ROOT), + ), + ConfigurableSource { override val useLoadMoreRequest = LoadMoreStrategy.Never override val useNewChapterEndpoint = true override val mangaSubString = "truyen-tranh" + + private val preferences: SharedPreferences = + Injekt.get().getSharedPreferences("source_$id", 0x0000) + + init { + preferences.getString(DEFAULT_BASE_URL_PREF, null).let { prefDefaultBaseUrl -> + if (prefDefaultBaseUrl != super.baseUrl) { + preferences.edit() + .putString(BASE_URL_PREF, super.baseUrl) + .putString(DEFAULT_BASE_URL_PREF, super.baseUrl) + .apply() + } + } + } + + override val baseUrl by lazy { getPrefBaseUrl() } + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + val baseUrlPref = androidx.preference.EditTextPreference(screen.context).apply { + key = BASE_URL_PREF + title = BASE_URL_PREF_TITLE + summary = BASE_URL_PREF_SUMMARY + setDefaultValue(super.baseUrl) + dialogTitle = BASE_URL_PREF_TITLE + dialogMessage = "Default: ${super.baseUrl}" + + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, RESTART_APP, Toast.LENGTH_LONG).show() + true + } + } + screen.addPreference(baseUrlPref) + } + + private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, super.baseUrl)!! + + companion object { + private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl" + private const val RESTART_APP = "Khởi chạy lại ứng dụng để áp dụng thay đổi." + private const val BASE_URL_PREF_TITLE = "Ghi đè URL cơ sở" + private const val BASE_URL_PREF = "overrideBaseUrl" + private const val BASE_URL_PREF_SUMMARY = + "Dành cho sử dụng tạm thời, cập nhật tiện ích sẽ xóa cài đặt." + } } diff --git a/src/vi/xxmanhwa/build.gradle b/src/vi/xxmanhwa/build.gradle index 405d86303..82325297b 100644 --- a/src/vi/xxmanhwa/build.gradle +++ b/src/vi/xxmanhwa/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'XXManhwa' extClass = '.XxManhwa' - extVersionCode = 5 + extVersionCode = 6 isNsfw = true } diff --git a/src/vi/xxmanhwa/src/eu/kanade/tachiyomi/extension/vi/xxmanhwa/XxManhwa.kt b/src/vi/xxmanhwa/src/eu/kanade/tachiyomi/extension/vi/xxmanhwa/XxManhwa.kt index 861147e06..55c407f5a 100644 --- a/src/vi/xxmanhwa/src/eu/kanade/tachiyomi/extension/vi/xxmanhwa/XxManhwa.kt +++ b/src/vi/xxmanhwa/src/eu/kanade/tachiyomi/extension/vi/xxmanhwa/XxManhwa.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.extension.vi.xxmanhwa import android.app.Application +import android.widget.Toast +import androidx.preference.EditTextPreference import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.network.GET @@ -31,7 +33,9 @@ class XxManhwa : ParsedHttpSource(), ConfigurableSource { override val lang = "vi" - override val baseUrl = "https://google.xxmanhwa2.top" + private val defaultBaseUrl = "https://google.xxmanhwa2.top" + + override val baseUrl by lazy { getPrefBaseUrl() } override val supportsLatest = false @@ -187,6 +191,17 @@ class XxManhwa : ParsedHttpSource(), ConfigurableSource { override fun imageUrlParse(document: Document) = throw UnsupportedOperationException() + init { + preferences.getString(DEFAULT_BASE_URL_PREF, null).let { prefDefaultBaseUrl -> + if (prefDefaultBaseUrl != defaultBaseUrl) { + preferences.edit() + .putString(BASE_URL_PREF, defaultBaseUrl) + .putString(DEFAULT_BASE_URL_PREF, defaultBaseUrl) + .apply() + } + } + } + override fun setupPreferenceScreen(screen: PreferenceScreen) { SwitchPreferenceCompat(screen.context).apply { key = KEY_HIDE_PAID_CHAPTERS @@ -194,15 +209,37 @@ class XxManhwa : ParsedHttpSource(), ConfigurableSource { summary = "Ẩn các chương truyện cần nạp VIP để đọc.\n$baseUrl/thong-tin-cap-bac-tai-khoan" setDefaultValue(false) }.let(screen::addPreference) + + EditTextPreference(screen.context).apply { + key = BASE_URL_PREF + title = BASE_URL_PREF_TITLE + summary = BASE_URL_PREF_SUMMARY + setDefaultValue(defaultBaseUrl) + dialogTitle = BASE_URL_PREF_TITLE + dialogMessage = "Default: $defaultBaseUrl" + + setOnPreferenceChangeListener { _, _ -> + Toast.makeText(screen.context, RESTART_APP, Toast.LENGTH_LONG).show() + true + } + }.let(screen::addPreference) } private inline fun String.parseAs(): T = json.decodeFromString(this) + private fun getPrefBaseUrl(): String = preferences.getString(BASE_URL_PREF, defaultBaseUrl)!! + companion object { private const val KEY_HIDE_PAID_CHAPTERS = "hidePaidChapters" // The website generates this by creating a canvas, doing some funny things to it, and then // gets the SHA256 of the canvas' data URI. Pretty much a static string until the site updates. private const val WP_NONCE = "e732af2390628a21d8b7500e621b1493c28d9330b415e88f27b8b4e2f9a440a3" + private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl" + private const val RESTART_APP = "Khởi chạy lại ứng dụng để áp dụng thay đổi." + private const val BASE_URL_PREF_TITLE = "Ghi đè URL cơ sở" + private const val BASE_URL_PREF = "overrideBaseUrl" + private const val BASE_URL_PREF_SUMMARY = + "Dành cho sử dụng tạm thời, cập nhật tiện ích sẽ xóa cài đặt." } }