diff --git a/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt b/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt
index 57bd827a8..357fe46bd 100644
--- a/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt
+++ b/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt
@@ -60,6 +60,18 @@ class PatchOptions : ResourcePatch {
)
)
+ /**
+ * Custom Double-tap to seek Values
+ */
+ internal var CustomDoubleTapLengthArrays: String? by option(
+ PatchOption.StringOption(
+ key = "CustomDoubleTapLengthArrays",
+ default = "3, 5, 10, 15, 20, 30, 60, 120, 180",
+ title = "Double-tap to seek Values",
+ description = "A list of custom double-tap to seek lengths. Be sure to separate them with commas (,)."
+ )
+ )
+
/**
* Custom Speed Values
*/
diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/doubletaplength/patch/DoubleTapLengthPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/doubletaplength/patch/DoubleTapLengthPatch.kt
new file mode 100644
index 000000000..0363d3174
--- /dev/null
+++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/doubletaplength/patch/DoubleTapLengthPatch.kt
@@ -0,0 +1,67 @@
+package app.revanced.patches.youtube.layout.etc.doubletaplength.patch
+
+import app.revanced.patcher.annotation.Description
+import app.revanced.patcher.annotation.Name
+import app.revanced.patcher.annotation.Version
+import app.revanced.patcher.data.ResourceContext
+import app.revanced.patcher.patch.PatchResult
+import app.revanced.patcher.patch.PatchResultError
+import app.revanced.patcher.patch.PatchResultSuccess
+import app.revanced.patcher.patch.ResourcePatch
+import app.revanced.patcher.patch.annotations.DependsOn
+import app.revanced.patcher.patch.annotations.Patch
+import app.revanced.patches.shared.annotation.YouTubeCompatibility
+import app.revanced.patches.shared.patch.options.PatchOptions
+import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
+import app.revanced.util.resources.ResourceHelper.addEntryValues
+import app.revanced.util.resources.ResourceUtils
+import app.revanced.util.resources.ResourceUtils.copyResources
+import app.revanced.util.resources.ResourceUtils.copyXmlNode
+
+@Patch
+@Name("custom-double-tap-length")
+@Description("Add 'double-tap to seek' value.")
+@DependsOn(
+ [
+ PatchOptions::class,
+ SettingsPatch::class
+ ]
+)
+@YouTubeCompatibility
+@Version("0.0.1")
+class DoubleTapLengthPatch : ResourcePatch {
+ override fun execute(context: ResourceContext): PatchResult {
+
+ /**
+ * Copy arrays
+ */
+ context.copyResources(
+ "youtube/doubletap",
+ ResourceUtils.ResourceGroup(
+ "values-v21",
+ "arrays.xml"
+ )
+ )
+
+ val speed = PatchOptions.CustomDoubleTapLengthArrays
+ ?: return PatchResultError("Invalid double-tap length array.")
+
+ val splits = speed.replace(" ","").split(",")
+ if (splits.isEmpty()) throw IllegalArgumentException("Invalid speed elements")
+ val speedElements = splits.map { it }
+ for (index in 0 until splits.count()) {
+ context.addEntryValues(TARGET_ARRAY_PATH, speedElements[index], TARGET_ENTRY_VALUE_NAME)
+ context.addEntryValues(TARGET_ARRAY_PATH, speedElements[index], TARGET_ENTRIES_NAME)
+ }
+
+ SettingsPatch.updatePatchStatus("custom-double-tap-length")
+
+ return PatchResultSuccess()
+ }
+
+ private companion object {
+ private const val TARGET_ARRAY_PATH = "res/values-v21/arrays.xml"
+ private const val TARGET_ENTRIES_NAME = "double_tap_length_entries"
+ private const val TARGET_ENTRY_VALUE_NAME = "double_tap_length_values"
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/resource/patch/CustomVideoSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/resource/patch/CustomVideoSpeedPatch.kt
index 8992c32a7..28d23d676 100644
--- a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/resource/patch/CustomVideoSpeedPatch.kt
+++ b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/resource/patch/CustomVideoSpeedPatch.kt
@@ -14,8 +14,8 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.patch.options.PatchOptions
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.patches.youtube.video.customspeed.bytecode.patch.CustomVideoSpeedBytecodePatch
-import app.revanced.util.resources.ResourceHelper.addSpeedEntries
-import app.revanced.util.resources.ResourceHelper.addSpeedEntryValues
+import app.revanced.util.resources.ResourceHelper.addEntries
+import app.revanced.util.resources.ResourceHelper.addEntryValues
import app.revanced.util.resources.ResourceUtils.copyXmlNode
@Patch
@@ -45,8 +45,8 @@ class CustomVideoSpeedPatch : ResourcePatch {
if (splits.isEmpty()) throw IllegalArgumentException("Invalid speed elements")
val speedElements = splits.map { it }
for (index in 0 until splits.count()) {
- context.addSpeedEntries(speedElements[index] + "x")
- context.addSpeedEntryValues(speedElements[index])
+ context.addEntries(TARGET_ARRAY_PATH, speedElements[index] + "x", TARGET_ENTRY_VALUE_NAME)
+ context.addEntryValues(TARGET_ARRAY_PATH, speedElements[index], TARGET_ENTRIES_NAME)
}
/*
@@ -63,4 +63,9 @@ class CustomVideoSpeedPatch : ResourcePatch {
return PatchResultSuccess()
}
+ private companion object {
+ private const val TARGET_ARRAY_PATH = "res/values/arrays.xml"
+ private const val TARGET_ENTRIES_NAME = "revanced_custom_video_speed_entry"
+ private const val TARGET_ENTRY_VALUE_NAME = "revanced_custom_video_speed_entry_value"
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt b/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt
index 9ec28652d..710963ef3 100644
--- a/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt
+++ b/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt
@@ -16,8 +16,6 @@ private fun Node.insertNode(tagName: String, targetNode: Node, block: Element.()
internal object ResourceHelper {
- private const val TARGET_ARRAY_PATH = "res/values/arrays.xml"
-
private const val TARGET_PREFERENCE_PATH = "res/xml/revanced_prefs.xml"
private const val YOUTUBE_SETTINGS_PATH = "res/xml/settings_fragment.xml"
@@ -28,8 +26,12 @@ internal object ResourceHelper {
targetPackage = newPackage
}
- internal fun ResourceContext.addSpeedEntryValues(speedEntryValues: String) {
- xmlEditor[TARGET_ARRAY_PATH].use {
+ internal fun ResourceContext.addEntryValues(
+ path: String,
+ speedEntryValues: String,
+ attributeName: String
+ ) {
+ xmlEditor[path].use {
with(it.file) {
val resourcesNode = getElementsByTagName("resources").item(0) as Element
@@ -38,7 +40,7 @@ internal object ResourceHelper {
for (i in 0 until resourcesNode.childNodes.length) {
val node = resourcesNode.childNodes.item(i) as? Element ?: continue
- if (node.getAttribute("name") == "revanced_custom_video_speed_entry_value") {
+ if (node.getAttribute("name") == attributeName) {
newElement.appendChild(createTextNode(speedEntryValues))
node.appendChild(newElement)
@@ -48,8 +50,12 @@ internal object ResourceHelper {
}
}
- internal fun ResourceContext.addSpeedEntries(speedEntries: String) {
- xmlEditor[TARGET_ARRAY_PATH].use {
+ internal fun ResourceContext.addEntries(
+ path: String,
+ speedEntries: String,
+ attributeName: String
+ ) {
+ xmlEditor[path].use {
with(it.file) {
val resourcesNode = getElementsByTagName("resources").item(0) as Element
@@ -58,7 +64,7 @@ internal object ResourceHelper {
for (i in 0 until resourcesNode.childNodes.length) {
val node = resourcesNode.childNodes.item(i) as? Element ?: continue
- if (node.getAttribute("name") == "revanced_custom_video_speed_entry") {
+ if (node.getAttribute("name") == attributeName) {
newElement.appendChild(createTextNode(speedEntries))
node.appendChild(newElement)
@@ -66,8 +72,8 @@ internal object ResourceHelper {
}
}
}
- this[TARGET_ARRAY_PATH].writeText(
- this[TARGET_ARRAY_PATH].readText().replace("1.0x", "@string/shorts_speed_control_normal_label")
+ this[path].writeText(
+ this[path].readText().replace("1.0x", "@string/shorts_speed_control_normal_label")
)
}
diff --git a/src/main/resources/youtube/doubletap/values-v21/arrays.xml b/src/main/resources/youtube/doubletap/values-v21/arrays.xml
new file mode 100644
index 000000000..55da605c3
--- /dev/null
+++ b/src/main/resources/youtube/doubletap/values-v21/arrays.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml
index 98e22b129..43d2b8511 100644
--- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml
+++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml
@@ -550,7 +550,7 @@
-
+