include IITC in the app’s resources and load it from there
IITC can only be updated with the app from now on, as the remote-loading code has been removed. The new injection method intercepts all resources being requested by the web page and either injects our code or and empty string. This should stop IITCM from requesting them at all, saving band- width and reducing the boot up time dramatically.
This commit is contained in:
parent
70211b700c
commit
6f2f1302be
1
mobile/.gitignore
vendored
1
mobile/.gitignore
vendored
@ -1,7 +1,6 @@
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
assets/
|
||||
bin/
|
||||
gen/
|
||||
libs/
|
||||
|
1
mobile/assets/iitc.js
Symbolic link
1
mobile/assets/iitc.js
Symbolic link
@ -0,0 +1 @@
|
||||
../../iitc-debug.user.js
|
@ -15,7 +15,7 @@ public class IITC_WebView extends WebView {
|
||||
private IITC_WebViewClient webclient;
|
||||
|
||||
// init web view
|
||||
private void iitc_init() {
|
||||
private void iitc_init(Context c) {
|
||||
settings = this.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
settings.setDomStorageEnabled(true);
|
||||
@ -31,7 +31,7 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
});
|
||||
|
||||
webclient = new IITC_WebViewClient();
|
||||
webclient = new IITC_WebViewClient(c);
|
||||
this.setWebViewClient(webclient);
|
||||
}
|
||||
|
||||
@ -39,19 +39,19 @@ public class IITC_WebView extends WebView {
|
||||
public IITC_WebView(Context context) {
|
||||
super(context);
|
||||
|
||||
iitc_init();
|
||||
iitc_init(context);
|
||||
}
|
||||
|
||||
public IITC_WebView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
iitc_init();
|
||||
iitc_init(context);
|
||||
}
|
||||
|
||||
public IITC_WebView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
iitc_init();
|
||||
iitc_init(context);
|
||||
}
|
||||
//----------------------------------------------------------------
|
||||
|
||||
|
@ -1,13 +1,50 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.http.SslError;
|
||||
import android.util.Log;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.SslErrorHandler;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.StringBufferInputStream;
|
||||
|
||||
public class IITC_WebViewClient extends WebViewClient {
|
||||
private static final StringBufferInputStream style = new StringBufferInputStream(
|
||||
"body, #dashboard_container, #map_canvas { background: #000 !important; }");
|
||||
private static final StringBufferInputStream empty = new StringBufferInputStream("");
|
||||
|
||||
private static WebResourceResponse iitcjs;
|
||||
|
||||
public IITC_WebViewClient(Context c) throws java.io.IOException {
|
||||
loadIITC_JS(c);
|
||||
}
|
||||
|
||||
private static void loadIITC_JS(Context c) throws java.io.IOException {
|
||||
InputStream input;
|
||||
input = c.getAssets().open("iitc.js");
|
||||
|
||||
int size = input.available();
|
||||
byte[] buffer = new byte[size];
|
||||
input.read(buffer);
|
||||
input.close();
|
||||
String js = new String(buffer);
|
||||
// need to wrap the mobile iitc.js version in a document ready. IITC
|
||||
// expects to be injected after the DOM has been loaded completely.
|
||||
// Since the mobile client injects IITC by replacing the gen_dashboard
|
||||
// file, IITC runs to early. The document.ready delays IITC long enough
|
||||
// so it boots correctly.
|
||||
js = "$(document).ready(function(){" + js + "});";
|
||||
|
||||
iitcjs = new WebResourceResponse(
|
||||
"text/javascript",
|
||||
"UTF-8",
|
||||
new StringBufferInputStream(js)
|
||||
);
|
||||
};
|
||||
|
||||
// enable https
|
||||
@Override
|
||||
@ -15,23 +52,27 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
handler.proceed() ;
|
||||
};
|
||||
|
||||
// injecting IITC when page is loaded
|
||||
// Check every external resource if it’s okay to load it and maybe replace it
|
||||
// with our own content. This is used to block loading Niantic resources
|
||||
// which aren’t required and to inject IITC early into the site.
|
||||
// via http://stackoverflow.com/a/8274881/1684530
|
||||
@Override
|
||||
public void onPageFinished(WebView web, String Url) {
|
||||
Log.d("loading finish", web.getUrl());
|
||||
if (web.getUrl().contains("ingress.com/intel") && !web.getUrl().contains("accounts")) {
|
||||
// first check for cookies, than inject javascript
|
||||
// this enables the user to login if necessary
|
||||
CookieManager cm = CookieManager.getInstance();
|
||||
final String cookie = cm.getCookie("https://www.ingress.com/intel");
|
||||
if(cookie != null) {
|
||||
web.loadUrl("javascript: (function() { "
|
||||
+ "var script=document.createElement('script');"
|
||||
+ "script.type='text/javascript';"
|
||||
+ "script.src='https://iitcserv.appspot.com/iitc-nightly/iitc-nightly-latest.user.js';"
|
||||
+ "document.getElementsByTagName('head').item(0).appendChild(script);"
|
||||
+ "})()");
|
||||
}
|
||||
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
|
||||
if(url.contains("/css/common.css")) {
|
||||
return new WebResourceResponse("text/css", "UTF-8", style);
|
||||
} else if(url.contains("gen_dashboard.js")) {
|
||||
return this.iitcjs;
|
||||
} else if(url.contains("/css/ap_icons.css")
|
||||
|| url.contains("/css/map_icons.css")
|
||||
|| url.contains("/css/misc_icons.css")
|
||||
|| url.contains("/css/style_full.css")
|
||||
|| url.contains("/css/style_mobile.css")
|
||||
|| url.contains("/css/portalrender.css")
|
||||
|| url.contains("js/analytics.js")
|
||||
|| url.contains("google-analytics.com/ga.js")) {
|
||||
return new WebResourceResponse("text/plain", "UTF-8", empty);
|
||||
} else {
|
||||
return super.shouldInterceptRequest(view, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user