show additional plugins in plugins dialog (closes #327)
This commit is contained in:
@ -397,7 +397,7 @@ public class IITC_Mobile extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private void injectJS() {
|
||||
private void loadIITC() {
|
||||
try {
|
||||
iitc_view.getWebViewClient().loadIITC_JS(this);
|
||||
} catch (IOException e1) {
|
||||
@ -419,8 +419,7 @@ public class IITC_Mobile extends Activity {
|
||||
// plugins are injected onPageFinished
|
||||
public void loadUrl(String url) {
|
||||
url = addUrlParam(url);
|
||||
Log.d("iitcm", "injecting main-script...");
|
||||
injectJS();
|
||||
loadIITC();
|
||||
iitc_view.loadUrl(url);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
@ -7,6 +9,8 @@ import java.util.Scanner;
|
||||
import android.app.Activity;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class IITC_Settings extends Activity {
|
||||
@ -46,24 +50,36 @@ public class IITC_Settings extends Activity {
|
||||
}
|
||||
if (s != null)
|
||||
src = s.hasNext() ? s.next() : "";
|
||||
String header = src.substring(src.indexOf("==UserScript=="),
|
||||
src.indexOf("==/UserScript=="));
|
||||
// remove new line comments and replace with space
|
||||
// this way we get double spaces instead of newline + double slash
|
||||
header = header.replace("\n//", " ");
|
||||
// get a list of key-value...split on multiple spaces
|
||||
String[] attributes = header.split(" +");
|
||||
String plugin_name = "not found";
|
||||
for (int j = 0; j < attributes.length; j++) {
|
||||
// search for name and use the value
|
||||
if (attributes[j].equals("@name"))
|
||||
plugin_name = attributes[j + 1];
|
||||
}
|
||||
String plugin_name = getPluginName(src);
|
||||
asset_list.add(plugin_name);
|
||||
// real value
|
||||
asset_values.add(asset_array[i]);
|
||||
}
|
||||
|
||||
// load additional plugins from <storage-path>/IITC_Mobile/plugins/
|
||||
String iitc_path = Environment.getExternalStorageDirectory().getPath()
|
||||
+ "/IITC_Mobile/";
|
||||
File directory = new File(iitc_path + "plugins/");
|
||||
File[] files = directory.listFiles();
|
||||
if (files != null) {
|
||||
Scanner s = null;
|
||||
String src = "";
|
||||
for (int i = 0; i < files.length; ++i) {
|
||||
try {
|
||||
s = new Scanner(files[i]).useDelimiter("\\A");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.d("iitcm", "failed to parse file " + files[i]);
|
||||
}
|
||||
if (s != null)
|
||||
src = s.hasNext() ? s.next() : "";
|
||||
String plugin_name = getPluginName(src);
|
||||
asset_list.add("[User] " + plugin_name);
|
||||
// real value
|
||||
asset_values.add(files[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
bundle.putStringArray("ASSETS",
|
||||
(String[]) asset_list.toArray(new String[0]));
|
||||
@ -76,6 +92,24 @@ public class IITC_Settings extends Activity {
|
||||
.replace(android.R.id.content, settings).commit();
|
||||
}
|
||||
|
||||
// parse header for @name of plugin
|
||||
public String getPluginName(String src) {
|
||||
String header = src.substring(src.indexOf("==UserScript=="),
|
||||
src.indexOf("==/UserScript=="));
|
||||
// remove new line comments and replace with space
|
||||
// this way we get double spaces instead of newline + double slash
|
||||
header = header.replace("\n//", " ");
|
||||
// get a list of key-value...split on multiple spaces
|
||||
String[] attributes = header.split(" +");
|
||||
String plugin_name = "not found";
|
||||
for (int j = 0; j < attributes.length; j++) {
|
||||
// search for name and use the value
|
||||
if (attributes[j].equals("@name"))
|
||||
plugin_name = attributes[j + 1];
|
||||
}
|
||||
return plugin_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
@ -71,18 +71,15 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
|
||||
// if developer mode are enabled, load all iitc script from external
|
||||
// storage
|
||||
Log.d("iitcm", "adding iitc main script");
|
||||
if (sharedPref.getBoolean("pref_dev_checkbox", false)) {
|
||||
js = this.fileToString(iitc_path
|
||||
+ "dev/total-conversion-build.user.js", false);
|
||||
if (js.equals("false")) {
|
||||
Toast.makeText(
|
||||
context,
|
||||
"File "
|
||||
+ iitc_path
|
||||
+ "dev/total-conversion-build.user.js not found. "
|
||||
+ "Disable developer mode or add iitc files "
|
||||
+ "to the dev folder.", Toast.LENGTH_LONG)
|
||||
.show();
|
||||
Toast.makeText( context, "File " + iitc_path +
|
||||
"dev/total-conversion-build.user.js not found. " +
|
||||
"Disable developer mode or add iitc files to the dev folder.",
|
||||
Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
} else {
|
||||
Toast.makeText(context, "Developer mode enabled",
|
||||
@ -153,12 +150,19 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
String[] plugin_array = plugin_list.toArray(new String[0]);
|
||||
|
||||
for (int i = 0; i < plugin_list.size(); i++) {
|
||||
Log.d("iitcm", "adding plugin " + plugin_array[i]);
|
||||
if (dev_enabled)
|
||||
js += this.removePluginWrapper(iitc_path + "dev/plugins/"
|
||||
+ plugin_array[i], false);
|
||||
else
|
||||
js += this.removePluginWrapper("plugins/" + plugin_array[i], true);
|
||||
// load default iitc plugins
|
||||
if (!plugin_array[i].startsWith(iitc_path)) {
|
||||
Log.d("iitcm", "adding plugin " + plugin_array[i]);
|
||||
if (dev_enabled)
|
||||
js += this.removePluginWrapper(iitc_path + "dev/plugins/"
|
||||
+ plugin_array[i], false);
|
||||
else
|
||||
js += this.removePluginWrapper("plugins/" + plugin_array[i], true);
|
||||
// load additional iitc plugins
|
||||
} else {
|
||||
Log.d("iitcm", "adding additional plugin " + plugin_array[i]);
|
||||
js += this.removePluginWrapper(plugin_array[i], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,19 +170,6 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
if (sharedPref.getBoolean("pref_user_loc", false))
|
||||
js += parseTrackingPlugin(dev_enabled);
|
||||
|
||||
// load additional plugins from <storage-path>/IITC-Mobile/plugins/
|
||||
File directory = new File(iitc_path + "plugins/");
|
||||
File[] files = directory.listFiles();
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length; ++i) {
|
||||
String add_js = "";
|
||||
if ((add_js = this.removePluginWrapper(files[i].toString(), false)) != "") {
|
||||
Log.d("iitcm",
|
||||
"loading additional plugin " + files[i].toString());
|
||||
js += add_js;
|
||||
}
|
||||
}
|
||||
}
|
||||
return js;
|
||||
}
|
||||
|
||||
@ -281,6 +272,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
if (url.contains("/css/common.css")) {
|
||||
return new WebResourceResponse("text/css", "UTF-8", style);
|
||||
} else if (url.contains("gen_dashboard.js")) {
|
||||
Log.d("iitcm", "replacing gen_dashboard.js with iitc script");
|
||||
Log.d("iitcm", "injecting iitc...");
|
||||
return this.iitcjs;
|
||||
} else if (url.contains("/css/ap_icons.css")
|
||||
|| url.contains("/css/map_icons.css")
|
||||
|
Reference in New Issue
Block a user