From 02af60dcf580d92c2b50dea59b6b592629403fda Mon Sep 17 00:00:00 2001 From: Chopper <156493704+ttony2chopper@users.noreply.github.com> Date: Sun, 26 May 2024 04:55:29 -0300 Subject: [PATCH] MangaMate: Add random user agent (#3231) * Add random user agent * Cleanup --- src/ja/mangamate/build.gradle | 6 ++- .../extension/ja/mangamate/MangaMate.kt | 42 ++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/ja/mangamate/build.gradle b/src/ja/mangamate/build.gradle index bd97ce782..e7f8f481e 100644 --- a/src/ja/mangamate/build.gradle +++ b/src/ja/mangamate/build.gradle @@ -3,8 +3,12 @@ ext { extClass = '.MangaMate' themePkg = 'mangathemesia' baseUrl = 'https://manga-mate.org' - overrideVersionCode = 0 + overrideVersionCode = 1 isNsfw = true } apply from: "$rootDir/common.gradle" + +dependencies { + implementation project(':lib:randomua') +} diff --git a/src/ja/mangamate/src/eu/kanade/tachiyomi/extension/ja/mangamate/MangaMate.kt b/src/ja/mangamate/src/eu/kanade/tachiyomi/extension/ja/mangamate/MangaMate.kt index a0860337d..de3639b6b 100644 --- a/src/ja/mangamate/src/eu/kanade/tachiyomi/extension/ja/mangamate/MangaMate.kt +++ b/src/ja/mangamate/src/eu/kanade/tachiyomi/extension/ja/mangamate/MangaMate.kt @@ -1,14 +1,44 @@ package eu.kanade.tachiyomi.extension.ja.mangamate +import android.app.Application +import android.content.SharedPreferences +import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.lib.randomua.addRandomUAPreferenceToScreen +import eu.kanade.tachiyomi.lib.randomua.getPrefCustomUA +import eu.kanade.tachiyomi.lib.randomua.getPrefUAType +import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia +import eu.kanade.tachiyomi.network.interceptor.rateLimit +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 MangaMate : MangaThemesia( - "漫画メイト", - "https://manga-mate.org", - "ja", - dateFormat = SimpleDateFormat("MMMM d, yyyy", Locale("ja")), -) { +class MangaMate : + MangaThemesia( + "漫画メイト", + "https://manga-mate.org", + "ja", + dateFormat = SimpleDateFormat("MMMM d, yyyy", Locale("ja")), + ), + ConfigurableSource { + + private val preferences: SharedPreferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } + + override val client = super.client.newBuilder() + .setRandomUserAgent( + preferences.getPrefUAType(), + preferences.getPrefCustomUA(), + ) + .rateLimit(3) + .build() + override val seriesAuthorSelector = ".fmed b:contains(作者) + span" + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + addRandomUAPreferenceToScreen(screen) + } }