Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yaoi Manga Online: Remove author name from title #7016

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/all/yaoimangaonline/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Yaoi Manga Online'
extClass = '.YaoiMangaOnline'
extVersionCode = 3
extVersionCode = 4
isNsfw = true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package eu.kanade.tachiyomi.extension.all.yaoimangaonline

import android.app.Application
import android.content.SharedPreferences
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
Expand All @@ -10,8 +15,10 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

class YaoiMangaOnline : ParsedHttpSource() {
class YaoiMangaOnline : ParsedHttpSource(), ConfigurableSource {
override val lang = "all"

override val name = "Yaoi Manga Online"
Expand All @@ -21,6 +28,10 @@ class YaoiMangaOnline : ParsedHttpSource() {
// Popular is actually latest
override val supportsLatest = false

private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}

override fun latestUpdatesSelector() = popularMangaSelector()

override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector()
Expand Down Expand Up @@ -70,9 +81,16 @@ class YaoiMangaOnline : ParsedHttpSource() {
thumbnail_url = element.selectFirst("img")?.attr("src")
}

private var titleRegex: Regex =
Regex("(?s)(by\\b(?:(?!by\\b).)*\$)", RegexOption.IGNORE_CASE)

override fun mangaDetailsParse(document: Document) =
SManga.create().apply {
title = document.select("h1.entry-title").text()
if (isRemoveTitleVersion()) {
title = title.replace(titleRegex, "").trim()
}

thumbnail_url = document
.selectFirst(".herald-post-thumbnail img")?.attr("src")
description = document.select(".entry-content > p").text()
Expand Down Expand Up @@ -107,4 +125,19 @@ class YaoiMangaOnline : ParsedHttpSource() {

override fun getFilterList() =
FilterList(CategoryFilter(), TagFilter())

private fun isRemoveTitleVersion() = preferences.getBoolean(REMOVE_TITLE_VERSION_PREF, false)

override fun setupPreferenceScreen(screen: PreferenceScreen) {
kana-shii marked this conversation as resolved.
Show resolved Hide resolved
SwitchPreferenceCompat(screen.context).apply {
key = REMOVE_TITLE_VERSION_PREF
title = "Remove author name from title"
summary = "This removes the author's name from titles"
setDefaultValue(false)
}.let(screen::addPreference)
}

companion object {
private const val REMOVE_TITLE_VERSION_PREF = "REMOVE_TITLE_VERSION"
}
}
Loading