mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-27 22:21:01 +00:00
Initial commit
This commit is contained in:
27
app/src/main/java/ani/dantotsu/others/webview/CloudFlare.kt
Normal file
27
app/src/main/java/ani/dantotsu/others/webview/CloudFlare.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
package ani.dantotsu.others.webview
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import ani.dantotsu.FileUrl
|
||||
|
||||
class CloudFlare(override val location: FileUrl) : WebViewBottomDialog() {
|
||||
val cfTag = "cf_clearance"
|
||||
|
||||
override var title = "Cloudflare Bypass"
|
||||
override val webViewClient = object : WebViewClient() {
|
||||
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||
val cookie = cookies.getCookie(url.toString())
|
||||
if (cookie?.contains(cfTag) == true) {
|
||||
val clearance = cookie.substringAfter("$cfTag=").substringBefore(";")
|
||||
privateCallback.invoke(mapOf(cfTag to clearance))
|
||||
}
|
||||
super.onPageStarted(view, url, favicon)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance(url: FileUrl) = CloudFlare(url)
|
||||
fun newInstance(url: String) = CloudFlare(FileUrl(url))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package ani.dantotsu.others.webview
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.CookieManager
|
||||
import android.webkit.WebViewClient
|
||||
import ani.dantotsu.BottomSheetDialogFragment
|
||||
import ani.dantotsu.FileUrl
|
||||
import ani.dantotsu.databinding.BottomSheetWebviewBinding
|
||||
import ani.dantotsu.defaultHeaders
|
||||
|
||||
abstract class WebViewBottomDialog : BottomSheetDialogFragment() {
|
||||
|
||||
abstract val location: FileUrl
|
||||
|
||||
private var _binding: BottomSheetWebviewBinding? = null
|
||||
open val binding get() = _binding!!
|
||||
|
||||
abstract val title: String
|
||||
abstract val webViewClient: WebViewClient
|
||||
|
||||
var callback: ((Map<String, String>) -> Unit)? = null
|
||||
|
||||
protected var privateCallback: ((Map<String, String>) -> Unit) = {
|
||||
callback?.invoke(it)
|
||||
_binding?.webView?.stopLoading()
|
||||
dismiss()
|
||||
}
|
||||
|
||||
val cookies: CookieManager = CookieManager.getInstance()
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
_binding = BottomSheetWebviewBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
binding.webViewTitle.text = title
|
||||
binding.webView.settings.apply {
|
||||
javaScriptEnabled = true
|
||||
userAgentString = defaultHeaders["User-Agent"]
|
||||
}
|
||||
cookies.setAcceptThirdPartyCookies(binding.webView, true)
|
||||
binding.webView.webViewClient = webViewClient
|
||||
binding.webView.loadUrl(location.url, location.headers)
|
||||
this.dismiss()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
_binding = null
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user