Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.anwar.livescore.ui.webview
- import android.graphics.Bitmap
- import android.os.Bundle
- import android.view.MotionEvent
- import android.webkit.WebView
- import android.webkit.WebViewClient
- import androidx.activity.ComponentActivity
- import androidx.activity.compose.setContent
- import androidx.compose.foundation.background
- import androidx.compose.foundation.layout.*
- import androidx.compose.material3.CircularProgressIndicator
- import androidx.compose.material3.MaterialTheme
- import androidx.compose.runtime.*
- import androidx.compose.ui.Alignment
- import androidx.compose.ui.Modifier
- import androidx.compose.ui.viewinterop.AndroidView
- class WebViewActivity : ComponentActivity() {
- private lateinit var webView: WebView
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- val url = intent.getStringExtra("url") ?: return
- setContent {
- WebViewScreen(url) { webViewInstance ->
- webView = webViewInstance
- }
- }
- }
- override fun onBackPressed() {
- if (webView.canGoBack()) {
- webView.goBack()
- } else {
- super.onBackPressed()
- }
- }
- }
- @Composable
- fun WebViewScreen(url: String, onWebViewCreated: (WebView) -> Unit) {
- var isLoading by remember { mutableStateOf(true) }
- Box(
- modifier = Modifier
- .fillMaxSize()
- .background(MaterialTheme.colorScheme.background)
- ) {
- AndroidView(
- factory = { context ->
- WebView(context).apply {
- webViewClient = object : WebViewClient() {
- override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
- super.onPageStarted(view, url, favicon)
- isLoading = true
- }
- override fun onPageFinished(view: WebView?, url: String?) {
- super.onPageFinished(view, url)
- isLoading = false
- // Inject JavaScript untuk menyembunyikan elemen
- view?.evaluateJavascript(
- """
- (function() {
- // Fungsi untuk menyembunyikan elemen
- function hideElement(selector) {
- const elements = document.querySelectorAll(selector);
- elements.forEach(function(element) {
- element.style.display = 'none';
- });
- }
- function removeElement(selector) {
- const elements = document.querySelectorAll(selector);
- elements.forEach(function(element) {
- element.remove();
- });
- }
- // Sembunyikan elemen yang tidak diinginkan
- hideElement('.banner-content-wrapper');
- hideElement('#tableStats');
- hideElement('#voteLeft');
- hideElement('#voteRight');
- hideElement('.adsbygoogle');
- hideElement('ins');
- hideElement('iframe');
- hideElement('.ads');
- hideElement('.ad-container');
- hideElement('#ads');
- hideElement('[id*="ads"]');
- hideElement('[class*="ads"]');
- // Sembunyikan tombol share
- hideElement('#facebookButton');
- hideElement('#whatsappButton');
- hideElement('[href*="facebook.com/sharer"]');
- hideElement('[href*="wa.me"]');
- hideElement('[style*="margin:2px;font-size:10px;text-align:center;"]');
- // Sembunyikan header liga
- hideElement('[style*="overflow: hidden;height: 18px;margin-top: 5px"]');
- hideElement('[style*="background-color: rgba(0, 0, 0, 0.5)"]');
- hideElement('.details');
- hideElement('img[src*="countryLeagues"]');
- // Hapus script ads
- removeElement('script[src*="adsbygoogle"]');
- removeElement('script[src*="pagead"]');
- // Tambahkan CSS untuk memastikan elemen tetap tersembunyi
- const style = document.createElement('style');
- style.textContent = `
- .banner-content-wrapper, #tableStats, #voteLeft, #voteRight,
- .adsbygoogle, ins, iframe, .ads, .ad-container, #ads,
- [id*="ads"], [class*="ads"],
- #facebookButton, #whatsappButton,
- [href*="facebook.com/sharer"], [href*="wa.me"],
- [style*="margin:2px;font-size:10px;text-align:center;"],
- [style*="overflow: hidden;height: 18px;margin-top: 5px"],
- [style*="background-color: rgba(0, 0, 0, 0.5)"],
- .details,
- img[src*="countryLeagues"] {
- display: none !important;
- visibility: hidden !important;
- opacity: 0 !important;
- pointer-events: none !important;
- height: 0 !important;
- margin: 0 !important;
- padding: 0 !important;
- }
- /* Hapus margin bawah yang tidak perlu */
- body {
- margin-bottom: 0 !important;
- padding-bottom: 0 !important;
- }
- /* Hapus div kosong di bawah */
- div[style*="clear:both;height:100px"] {
- display: none !important;
- }
- `;
- document.head.appendChild(style);
- // Jalankan fungsi ini setiap 1 detik untuk memastikan elemen tetap tersembunyi
- setInterval(function() {
- hideElement('#facebookButton');
- hideElement('#whatsappButton');
- hideElement('[href*="facebook.com/sharer"]');
- hideElement('[href*="wa.me"]');
- hideElement('[style*="margin:2px;font-size:10px;text-align:center;"]');
- hideElement('div[style*="clear:both;height:100px"]');
- hideElement('[style*="overflow: hidden;height: 18px;margin-top: 5px"]');
- hideElement('[style*="background-color: rgba(0, 0, 0, 0.5)"]');
- hideElement('.details');
- hideElement('img[src*="countryLeagues"]');
- }, 1000);
- })();
- """.trimIndent(),
- null
- )
- }
- }
- with(settings) {
- javaScriptEnabled = true
- domStorageEnabled = true
- userAgentString = "Mozilla/5.0 (Linux; Android 10; Mobile) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36"
- }
- loadUrl(url)
- onWebViewCreated(this)
- }
- },
- modifier = Modifier.fillMaxSize()
- )
- // Loading indicator
- if (isLoading) {
- Box(
- modifier = Modifier
- .fillMaxSize()
- .background(MaterialTheme.colorScheme.background.copy(alpha = 0.8f)),
- contentAlignment = Alignment.Center
- ) {
- CircularProgressIndicator(
- color = MaterialTheme.colorScheme.primary
- )
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement