This commit is contained in:
Jon Atkins 2013-10-09 07:39:39 +01:00
commit bfff03becd
4 changed files with 21 additions and 74 deletions

View File

@ -247,8 +247,6 @@ if buildMobile:
except:
pass
shutil.copy(os.path.join(outDir,"total-conversion-build.user.js"), "mobile/assets/total-conversion-build.user.js")
# copy the user location script into the mobile folder.
shutil.copy(os.path.join(outDir,"user-location.user.js"), "mobile/assets/user-location.user.js")
# also copy plugins
try:
shutil.rmtree("mobile/assets/plugins")
@ -260,6 +258,9 @@ if buildMobile:
'force-https*', 'privacy-view*', 'speech-search*',
'basemap-cloudmade*', 'scroll-wheel-zoom-disable*'))
# copy the user location script into the mobile folder.
shutil.copy(os.path.join(outDir,"user-location.user.js"), "mobile/assets/plugins/user-location.user.js")
if buildMobile != 'copyonly':
# now launch 'ant' to build the mobile project

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cradle.iitc_mobile"
android:versionCode="52"
android:versionName="0.7.2">
android:versionCode="53"
android:versionName="0.7.3">
<uses-sdk
android:minSdkVersion="14"

View File

@ -129,8 +129,6 @@ public class IITC_WebViewClient extends WebViewClient {
js = js.replace("window.showLayerChooser = true;",
"window.showLayerChooser = false");
}
// add all plugins to the script...inject plugins + main script simultaneously
js += parsePlugins();
// IITC expects to be injected after the DOM has been loaded completely.
// since it is injected with the onPageFinished() event, no further delay is necessary.
@ -151,6 +149,7 @@ public class IITC_WebViewClient extends WebViewClient {
|| url.startsWith("https://www.ingress.com/intel")) {
Log.d("iitcm", "injecting iitc..");
view.loadUrl("javascript: " + this.mIitcScript);
loadPlugins(view);
}
super.onPageFinished(view, url);
}
@ -166,14 +165,12 @@ public class IITC_WebViewClient extends WebViewClient {
//((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args);
}
// parse all enabled iitc plugins
// returns a string containing all plugins without their wrappers
public String parsePlugins() {
String js = "";
public void loadPlugins(WebView view) {
// get the plugin preferences
SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(mContext);
boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", false);
String path = (dev_enabled) ? mIitcPath + "dev/plugins/" : "plugins/";
Map<String, ?> all_prefs = sharedPref.getAll();
@ -181,39 +178,32 @@ public class IITC_WebViewClient extends WebViewClient {
for (Map.Entry<String, ?> entry : all_prefs.entrySet()) {
String plugin = entry.getKey();
if (plugin.endsWith("user.js") && entry.getValue().toString().equals("true")) {
// load default iitc plugins
if (!plugin.startsWith(mIitcPath)) {
// load default iitc plugins
Log.d("iitcm", "adding plugin " + plugin);
if (dev_enabled)
js += this.removePluginWrapper(mIitcPath + "dev/plugins/"
+ plugin, false);
else
js += this.removePluginWrapper("plugins/" + plugin, true);
// load user iitc plugins
loadJS(path + plugin, !dev_enabled, view);
} else {
// load user iitc plugins
Log.d("iitcm", "adding user plugin " + plugin);
js += this.removePluginWrapper(plugin, false);
loadJS(plugin, false, view);
}
}
}
// inject the user location script if enabled in settings
if (sharedPref.getBoolean("pref_user_loc", false))
js += parseTrackingPlugin(dev_enabled);
return js;
loadJS(path + "user-location.user.js", !dev_enabled, view);
}
public String parseTrackingPlugin(boolean dev_enabled) {
Log.d("iitcm", "enable tracking...");
String js = "";
// load plugin from external storage if dev mode are enabled
if (dev_enabled)
js = this.removePluginWrapper(mIitcPath + "dev/user-location.user.js", false);
// read a file into a string
// load it as javascript
public boolean loadJS(String file, boolean asset, WebView view) {
String js = fileToString(file, asset);
if (js.equals("false"))
return false;
else
// load plugin from asset folder
js = this.removePluginWrapper("user-location.user.js", true);
return js;
view.loadUrl("javascript:" + js);
return true;
}
// read a file into a string
@ -248,48 +238,6 @@ public class IITC_WebViewClient extends WebViewClient {
return src;
}
// read a file into a string
// load it as javascript
// at the moment not needed, but not bad to have it in the IITC_WebViewClient API
public boolean loadJS(String file, boolean asset, WebView view) {
if (!file.endsWith("user.js"))
return false;
String js = fileToString(file, asset);
if (js.equals("false"))
return false;
else
view.loadUrl("javascript:" + js);
return true;
}
// iitc and all plugins are loaded at the same time
// so remove the wrapper functions and injection code
// TODO: it only works if the plugin is coded with the iitc plugin template
public String removePluginWrapper(String file, boolean asset) {
if (!file.endsWith("user.js")) return "";
String js = fileToString(file, asset);
if (js.equals("false")) return "";
js = js.replaceAll("\r\n", "\n"); //convert CR-LF pairs to LF - windows format text files
js = js.replaceAll("\r", "\n"); //convert remaining CR to LF - Mac format files(?)
String wrapper_start = "function wrapper() {";
String wrapper_end = "} // wrapper end";
String injection_code = "// inject code into site context\n" +
"var script = document.createElement('script');\n" +
"script.appendChild(document.createTextNode('('+ wrapper +')();'));\n" +
"(document.body || document.head || document.documentElement).appendChild(script);";
if (js.contains(wrapper_start) && js.contains(wrapper_end) && js.contains(injection_code)) {
js = js.replace(wrapper_start, "");
// remove the wrapper function
js = js.replace(wrapper_end, "");
// and the code injection
js = js.replace(injection_code, "");
} else {
Log.d("iitcm", "Removal of wrapper/injection code failed for " + file);
return "";
}
return js;
}
// Check every external resource if its okay to load it and maybe replace
// it
// with our own content. This is used to block loading Niantic resources

View File

@ -75,8 +75,6 @@ Yes it is!
</ul>
Note:
<ul>
<li>The plugins wrapper function has to be identical to all other IITC plugins (IITCm removes it via search and replace).
Alternatively, you can use the @@PLUGINSTART@@ / @@PLUGINEND@@ macros or remove the wrapper by hand.</li>
<li>The filename has to end with *.user.js.</li>
<li>If you don't know where to find your home directory: Enable dev-mode in the settings and follow the hint.</li>
</ul>