Initial commit

This commit is contained in:
Finnley Somdahl
2023-10-17 18:42:43 -05:00
commit 21bfbfb139
520 changed files with 47819 additions and 0 deletions

View 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))
}
}

View File

@@ -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()
}
}