diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/DesktopClipeveryKoinApplication.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/DesktopClipeveryKoinApplication.kt index 29654684d..b8963562a 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/DesktopClipeveryKoinApplication.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/DesktopClipeveryKoinApplication.kt @@ -10,6 +10,7 @@ import com.clipevery.clip.ClipboardService import com.clipevery.clip.DesktopTransferableConsumer import com.clipevery.clip.TransferableConsumer import com.clipevery.clip.getDesktopClipboardService +import com.clipevery.clip.plugin.ConvertUrlPlugin import com.clipevery.clip.plugin.ImageHtmlCombinePlugin import com.clipevery.clip.plugin.MultiImagePlugin import com.clipevery.clip.plugin.SortPlugin @@ -129,7 +130,9 @@ object Dependencies { ImageItemService(), TextItemService(), UrlItemService() - ), listOf(UrlTextCombinePlugin, + ), listOf( + UrlTextCombinePlugin, + ConvertUrlPlugin, ImageHtmlCombinePlugin, MultiImagePlugin, SortPlugin diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/clip/plugin/ConvertUrlPlugin.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/plugin/ConvertUrlPlugin.kt new file mode 100644 index 000000000..8f3796dee --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/clip/plugin/ConvertUrlPlugin.kt @@ -0,0 +1,33 @@ +package com.clipevery.clip.plugin + +import com.clipevery.clip.ClipPlugin +import com.clipevery.clip.item.TextClipItem +import com.clipevery.clip.item.UrlClipItem +import com.clipevery.dao.clip.ClipAppearItem +import java.net.MalformedURLException +import java.net.URL + +object ConvertUrlPlugin: ClipPlugin { + override fun pluginProcess(clipAppearItems: List): List { + return clipAppearItems.map { + if (it is TextClipItem && isUrl(it.text)) { + UrlClipItem().apply { + this.identifier = it.identifier + this.url = it.text + this.md5 = it.md5 + } + } else { + it + } + } + } + + private fun isUrl(string: String): Boolean { + try { + URL(string) + return true + } catch (e: MalformedURLException) { + return false + } + } +} \ No newline at end of file