|
| 1 | +package com.example.app; |
| 2 | + |
| 3 | +import android.annotation.SuppressLint; |
| 4 | +import android.app.Activity; |
| 5 | +import android.os.Bundle; |
| 6 | +import android.webkit.WebSettings; |
| 7 | +import android.webkit.WebView; |
| 8 | +import android.webkit.WebViewClient; |
| 9 | +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| 10 | + |
| 11 | +public class MainActivity extends Activity { |
| 12 | + |
| 13 | + private WebView mWebView; |
| 14 | + private SwipeRefreshLayout mSwipeRefreshLayout; |
| 15 | + |
| 16 | + @Override |
| 17 | + @SuppressLint("SetJavaScriptEnabled") |
| 18 | + protected void onCreate(Bundle savedInstanceState) { |
| 19 | + super.onCreate(savedInstanceState); |
| 20 | + setContentView(R.layout.activity_main); |
| 21 | + |
| 22 | + mSwipeRefreshLayout = findViewById(R.id.swipe_refresh_layout); |
| 23 | + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| 24 | + @Override |
| 25 | + public void onRefresh() { |
| 26 | + mWebView.reload(); |
| 27 | + } |
| 28 | + }); |
| 29 | + |
| 30 | + mWebView = findViewById(R.id.activity_main_webview); |
| 31 | + WebSettings webSettings = mWebView.getSettings(); |
| 32 | + webSettings.setDomStorageEnabled(true); |
| 33 | + webSettings.setJavaScriptEnabled(true); |
| 34 | + mWebView.setWebViewClient(new MyWebViewClient()); |
| 35 | + |
| 36 | + // REMOTE RESOURCE |
| 37 | + mWebView.loadUrl("https://vlr.gg"); |
| 38 | + |
| 39 | + // LOCAL RESOURCE |
| 40 | + // mWebView.loadUrl("file:///android_asset/index.html"); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public void onBackPressed() { |
| 45 | + if(mWebView.canGoBack()) { |
| 46 | + mWebView.goBack(); |
| 47 | + } else { |
| 48 | + super.onBackPressed(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + private class MyWebViewClient extends WebViewClient { |
| 53 | + @Override |
| 54 | + public void onPageFinished(WebView view, String url) { |
| 55 | + super.onPageFinished(view, url); |
| 56 | + |
| 57 | + mSwipeRefreshLayout.setRefreshing(false); |
| 58 | + |
| 59 | + // Load and execute custom JavaScript from a URL |
| 60 | + String statsvlrJS = "(function statsvlrJS() {" + |
| 61 | + " var script = document.createElement(`script`);" + |
| 62 | + " script.type = `text/javascript`;" + |
| 63 | + " script.src = `https://raw.githubusercontent.com/krushna06/Stats-VLR/main/browser.js`;" + |
| 64 | + " var head = document.getElementsByTagName(`head`)[0];" + |
| 65 | + " if (!head) return;" + |
| 66 | + " head.appendChild(script);" + |
| 67 | + "})();"; |
| 68 | + view.evaluateJavascript(statsvlrJS, null); |
| 69 | + |
| 70 | + String statsvlrCSS = "(function statsvlrCSS() {" + |
| 71 | + " var style = document.createElement(`link`);" + |
| 72 | + " style.rel = `stylesheet`;" + |
| 73 | + " style.href = `https://raw.githubusercontent.com/krushna06/Stats-VLR/main/browser.css`;" + |
| 74 | + " var head = document.getElementsByTagName(`head`)[0];" + |
| 75 | + " if (!head) return;" + |
| 76 | + " head.appendChild(style);" + |
| 77 | + "})();"; |
| 78 | + view.evaluateJavascript(statsvlrCSS, null); |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments