feat(music): add return-youtube-dislike patch

This commit is contained in:
inotia00
2023-09-05 12:15:25 +09:00
parent 0a27088c8d
commit f97d6de1c5
11 changed files with 262 additions and 0 deletions

View File

@ -212,4 +212,46 @@ internal object MusicResourceHelper {
}
}
internal fun ResourceContext.hookPreference(
key: String,
fragment: String
) {
this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor ->
with(editor.file) {
doRecursively loop@{
if (it !is Element) return@loop
it.getAttributeNode("android:key")?.let { attribute ->
if (attribute.textContent == "settings_header_about_youtube_music" && it.getAttributeNode(
"app:allowDividerBelow"
).textContent == "false"
) {
it.insertNode("Preference", it) {
setAttribute("android:persistent", "false")
setAttribute(
"android:title",
"@string/" + key + "_title"
)
setAttribute("android:key", key)
setAttribute("android:fragment", fragment)
setAttribute("app:allowDividerAbove", "false")
setAttribute("app:allowDividerAbove", "false")
}
it.getAttributeNode("app:allowDividerBelow").textContent = "true"
return@loop
}
}
}
doRecursively loop@{
if (it !is Element) return@loop
it.getAttributeNode("app:allowDividerBelow")?.let { attribute ->
if (attribute.textContent == "true") {
attribute.textContent = "false"
}
}
}
}
}
}
}