From 06018278782d04112decee5fffe738ea3ef2e435 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Tue, 8 Oct 2013 23:04:23 +0200 Subject: [PATCH] reverted back to one-after-another plugin injection --- build.py | 5 +- mobile/AndroidManifest.xml | 4 +- .../iitc_mobile/IITC_WebViewClient.java | 84 ++++--------------- website/page/faq.php | 2 - 4 files changed, 21 insertions(+), 74 deletions(-) diff --git a/build.py b/build.py index 96212c5c..252bed6a 100755 --- a/build.py +++ b/build.py @@ -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 diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index d8fa1712..0b7c9866 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="53" + android:versionName="0.7.3"> all_prefs = sharedPref.getAll(); @@ -181,39 +178,32 @@ public class IITC_WebViewClient extends WebViewClient { for (Map.Entry 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 it’s okay to load it and maybe replace // it // with our own content. This is used to block loading Niantic resources diff --git a/website/page/faq.php b/website/page/faq.php index c5d2572a..e88156ea 100644 --- a/website/page/faq.php +++ b/website/page/faq.php @@ -75,8 +75,6 @@ Yes it is! Note:
    -
  • 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.
  • The filename has to end with *.user.js.
  • If you don't know where to find your home directory: Enable dev-mode in the settings and follow the hint.