From f228ad572d83ad31509285b3081218957c091c86 Mon Sep 17 00:00:00 2001 From: Creepler13 Date: Tue, 17 Dec 2024 06:39:04 +0100 Subject: [PATCH] Asurascans Hide Premium chapters (#6627) * Hide Premium chapters * default true, Formatting --- src/en/asurascans/build.gradle | 2 +- .../extension/en/asurascans/AsuraScans.kt | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/en/asurascans/build.gradle b/src/en/asurascans/build.gradle index 2d3605f8a..ec4cc84f2 100644 --- a/src/en/asurascans/build.gradle +++ b/src/en/asurascans/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Asura Scans' extClass = '.AsuraScans' - extVersionCode = 43 + extVersionCode = 44 } apply from: "$rootDir/common.gradle" diff --git a/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScans.kt b/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScans.kt index 284d980f3..22d038403 100644 --- a/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScans.kt +++ b/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScans.kt @@ -241,7 +241,8 @@ class AsuraScans : ParsedHttpSource(), ConfigurableSource { override fun chapterListRequest(manga: SManga) = mangaDetailsRequest(manga) - override fun chapterListSelector() = "div.scrollbar-thumb-themecolor > div.group" + override fun chapterListSelector() = + if (preferences.hidePremiumChapters()) "div.scrollbar-thumb-themecolor > div.group:not(:has(svg))" else "div.scrollbar-thumb-themecolor > div.group" override fun chapterFromElement(element: Element) = SChapter.create().apply { setUrlWithoutDomain(element.selectFirst("a")!!.attr("abs:href").toPermSlugIfNeeded()) @@ -288,6 +289,13 @@ class AsuraScans : ParsedHttpSource(), ConfigurableSource { summary = "Automatically update random numbers in manga URLs.\nHelps mitigating HTTP 404 errors during update and \"in library\" marks when browsing.\nNote: This setting may require clearing database in advanced settings and migrating all manga to the same source." setDefaultValue(true) }.let(screen::addPreference) + + SwitchPreferenceCompat(screen.context).apply { + key = PREF_HIDE_PREMIUM_CHAPTERS + title = "Hide premium chapters" + summary = "Hides the chapters that require a subscription to view" + setDefaultValue(true) + }.let(screen::addPreference) } private var SharedPreferences.slugMap: MutableMap @@ -306,6 +314,10 @@ class AsuraScans : ParsedHttpSource(), ConfigurableSource { } private fun SharedPreferences.dynamicUrl(): Boolean = getBoolean(PREF_DYNAMIC_URL, true) + private fun SharedPreferences.hidePremiumChapters(): Boolean = getBoolean( + PREF_HIDE_PREMIUM_CHAPTERS, + true, + ) private fun String.toPermSlugIfNeeded(): String { if (!preferences.dynamicUrl()) return this @@ -327,5 +339,6 @@ class AsuraScans : ParsedHttpSource(), ConfigurableSource { private val OLD_FORMAT_CHAPTER_REGEX = """^/(\d+-)?[^/]*-chapter-\d+(-\d+)*/?$""".toRegex() private const val PREF_SLUG_MAP = "pref_slug_map_2" private const val PREF_DYNAMIC_URL = "pref_dynamic_url" + private const val PREF_HIDE_PREMIUM_CHAPTERS = "pref_hide_premium_chapters" } }