diff --git a/build.py b/build.py index 05017116..8d64942b 100755 --- a/build.py +++ b/build.py @@ -8,7 +8,14 @@ import base64 import sys import os import shutil +import json +import shelve +import hashlib +try: + import urllib2 +except ImportError: + import urllib.request as urllib2 # load settings file from buildsettings import buildSettings @@ -66,6 +73,33 @@ def loaderRaw(var): fn = var.group(1) return readfile(fn) +def loaderMD(var): + fn = var.group(1) + # use different MD.dat's for python 2 vs 3 incase user switches versions, as they are not compatible + db = shelve.open('build/MDv' + str(sys.version_info.major) + '.dat') + if 'files' in db: + files = db['files'] + else: + files = {} + file = readfile(fn) + filemd5 = hashlib.md5(file.encode('utf8')).hexdigest() + # check if file has already been parsed by the github api + if fn in files and filemd5 in files[fn]: + # use the stored copy if nothing has changed to avoid hiting the api more then the 60/hour when not signed in + db.close() + return files[fn][filemd5] + else: + url = 'https://api.github.com/markdown' + payload = {'text': file, 'mode': 'markdown'} + headers = {'Content-Type': 'application/json'} + req = urllib2.Request(url, json.dumps(payload).encode('utf8'), headers) + md = urllib2.urlopen(req).read().decode('utf8').replace('\n', '').replace('\'', '\\\'') + files[fn] = {} + files[fn][filemd5] = md + db['files'] = files + db.close() + return md + def loaderImage(var): fn = var.group(1) return 'data:image/png;base64,{0}'.format(base64.encodestring(open(fn, 'rb').read()).decode('utf8').replace('\n', '')) @@ -86,6 +120,7 @@ def doReplacements(script,updateUrl,downloadUrl): script = re.sub('@@INCLUDERAW:([0-9a-zA-Z_./-]+)@@', loaderRaw, script) script = re.sub('@@INCLUDESTRING:([0-9a-zA-Z_./-]+)@@', loaderString, script) + script = re.sub('@@INCLUDEMD:([0-9a-zA-Z_./-]+)@@', loaderMD, script) script = re.sub('@@INCLUDEIMAGE:([0-9a-zA-Z_./-]+)@@', loaderImage, script) script = script.replace('@@BUILDDATE@@', buildDate) diff --git a/code/map_data.js b/code/map_data.js index 317d7877..91c6b4f0 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -47,7 +47,7 @@ window.requestData = function() { portalRenderLimit.init(); // finally send ajax requests $.each(tiles, function(ind, tls) { - data = { minLevelOfDetail: -1 }; + data = { zoom: map.getZoom() }; data.boundsParamsList = tls; window.requests.add(window.postAjax('getThinnedEntitiesV2', data, window.handleDataResponse, window.handleFailedRequest)); }); diff --git a/code/map_data_calc_tools.js b/code/map_data_calc_tools.js index 2f383197..eca1b7e9 100644 --- a/code/map_data_calc_tools.js +++ b/code/map_data_calc_tools.js @@ -1,5 +1,4 @@ - // MAP DATA REQUEST CALCULATORS ////////////////////////////////////// // Ingress Intel splits up requests for map data (portals, links, // fields) into tiles. To get data for the current viewport (i.e. what @@ -23,9 +22,9 @@ window.calculateR = function(convCenterLat) { } window.convertLatLngToPoint = function(latlng, magic, R) { - var x = (magic/2 + latlng.lng * magic / 360)*R; + var x = (magic + latlng.lng * magic / 180)*R; var l = Math.sin(latlng.lat * DEG2RAD); - var y = (magic/2 + 0.5*Math.log((1+l)/(1-l)) * -(magic / (2*Math.PI)))*R; + var y = (magic + Math.log((1+l)/(1-l)) * -(magic / (2*Math.PI)))*R; return {x: Math.floor(x/magic), y: Math.floor(y/magic)}; } @@ -35,13 +34,13 @@ window.convertPointToLatLng = function(x, y, magic, R) { // orig function put together from all over the place // lat: (2 * Math.atan(Math.exp((((y + 1) * magic / R) - (magic/ 2)) / (-1*(magic / (2 * Math.PI))))) - Math.PI / 2) / (Math.PI / 180), // shortened version by your favorite algebra program. - lat: (360*Math.atan(Math.exp(Math.PI - 2*Math.PI*(y+1)/R)))/Math.PI - 90, - lng: 360*x/R-180 + lat: (360*Math.atan(Math.exp(Math.PI - Math.PI*(y+1)/R)))/Math.PI - 90, + lng: 180*x/R-180 }; e.ne = { //lat: (2 * Math.atan(Math.exp(((y * magic / R) - (magic/ 2)) / (-1*(magic / (2 * Math.PI))))) - Math.PI / 2) / (Math.PI / 180), - lat: (360*Math.atan(Math.exp(Math.PI - 2*Math.PI*y/R)))/Math.PI - 90, - lng: 360*(x+1)/R-180 + lat: (360*Math.atan(Math.exp(Math.PI - Math.PI*y/R)))/Math.PI - 90, + lng: 180*(x+1)/R-180 }; return e; } @@ -49,20 +48,7 @@ window.convertPointToLatLng = function(x, y, magic, R) { // calculates the quad key for a given point. The point is not(!) in // lat/lng format. window.pointToQuadKey = function(x, y) { - var quadkey = []; - for(var c = window.map.getZoom(); c > 0; c--) { - // +-------+ quadrants are probably ordered like this - // | 0 | 1 | - // |---|---| - // | 2 | 3 | - // |---|---| - var quadrant = 0; - var e = 1 << c - 1; - (x & e) != 0 && quadrant++; // push right - (y & e) != 0 && (quadrant++, quadrant++); // push down - quadkey.push(quadrant); - } - return quadkey.join(""); + return window.map.getZoom() + "_" + x + "_" + y; } // given quadkey and bounds, returns the format as required by the diff --git a/code/utils_misc.js b/code/utils_misc.js index 6058a864..3b8be358 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -1,7 +1,8 @@ // UTILS + MISC /////////////////////////////////////////////////////// window.aboutIITC = function(){ - var v = '@@BUILDNAME@@-@@BUILDDATE@@' + var v = '@@BUILDNAME@@-@@BUILDDATE@@'; + var attrib = '@@INCLUDEMD:ATTRIBUTION.md@@'; var a = '' + '
About IITC
' + '
Ingress Intel Total Conversion
' @@ -20,8 +21,11 @@ window.aboutIITC = function(){ + ' MapQuest OSM tiles Courtesy of MapQuest ' + ' ' + '
' - + '
Version: ' + v + '
'; - alert(a); + + '
Version: ' + v + '
' + + '
' + + '
' + attrib + '
'; + alert(a, true, function() {$('.ui-dialog').removeClass('ui-dialog-aboutIITC');}); + $('.ui-dialog').addClass('ui-dialog-aboutIITC'); } diff --git a/main.js b/main.js index 42da45b7..f87807ad 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,7 @@ // ==UserScript== // @id ingress-intel-total-conversion@jonatkins // @name IITC: Ingress intel map total conversion -// @version 0.10.5.@@DATETIMEVERSION@@ +// @version 0.11.0.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ diff --git a/mobile/.gitignore b/mobile/.gitignore index a56e372f..42222e62 100644 --- a/mobile/.gitignore +++ b/mobile/.gitignore @@ -7,3 +7,4 @@ libs/ proguard-project.txt local.properties assets/iitc.js +assets/plugins/ diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 700a8745..4da3cd1a 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -56,7 +56,7 @@ public class IITC_Mobile extends Activity { if (Intent.ACTION_VIEW.equals(action)) { Uri uri = intent.getData(); String url = uri.toString(); - if (intent.getScheme().equals("http://")) + if (intent.getScheme().equals("http")) url = url.replace("http://", "https://"); Log.d("iitcm", "intent received url: " + url); if (url.contains("ingress.com")) { diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java b/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java index 6a72c476..a5684005 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Settings.java @@ -2,7 +2,7 @@ package com.cradle.iitc_mobile; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Scanner; import android.app.Activity; import android.content.res.AssetManager; @@ -25,22 +25,35 @@ public class IITC_Settings extends Activity { e.printStackTrace(); } - ArrayList asset_list = new ArrayList(Arrays.asList(asset_array)); + ArrayList asset_list = new ArrayList(); ArrayList asset_values = new ArrayList(); - for (int i = 0; i < asset_list.size();) { - try { - if (asset_list.get(i).endsWith("user.js")) { - asset_values.add(am.open("plugins/" + asset_list.get(i)).toString()); - i++; + for (int i = 0; i < asset_array.length ; i++) { + if (asset_array[i].endsWith("user.js")) { + // find user plugin name for user readable entries + Scanner s = null; + String src = ""; + try { + s = new Scanner(am.open("plugins/" + asset_array[i])).useDelimiter("\\A"); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); } - else { - asset_list.remove(i); - asset_values.add(am.open("plugins/" + asset_list.get(i)).toString()); + 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]; } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + asset_list.add(plugin_name); + // real value + asset_values.add(asset_array[i]); } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java index 702f59db..5a68f307 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java @@ -26,7 +26,7 @@ public class IITC_SettingsFragment extends PreferenceFragment { //plugins MultiSelectListPreference pref_plugins = (MultiSelectListPreference) findPreference("pref_plugins"); pref_plugins.setEntries(getArguments().getStringArray("ASSETS")); - pref_plugins.setEntryValues(getArguments().getStringArray("ASSETS")); + pref_plugins.setEntryValues(getArguments().getStringArray("ASSETS_VAL")); // set build version ListPreference pref_build_version = (ListPreference) findPreference("pref_build_version"); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 15873a28..d2a62897 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -46,7 +46,7 @@ public class IITC_WebViewClient extends WebViewClient { String[] attributes = header.split(" +"); String iitc_version = "not found"; for (int i = 0; i < attributes.length; i++) { - // search vor version and use the value + // search for version and use the value if (attributes[i].equals("@version")) iitc_version = attributes[i+1]; } return iitc_version; @@ -154,7 +154,8 @@ public class IITC_WebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.contains("ingress.com")) { - if (url.contains("ingress.com/intel") && url.contains("latE6") && url.contains("lngE6")) { + // reload iitc if a poslink is clicked inside the app + if (url.contains("intel?ll=") || (url.contains("latE6") && url.contains("lngE6"))) { Log.d("iitcm", "should be an internal clicked position link...reload script for: " + url); ((IITC_Mobile) context).loadUrl(url); } diff --git a/style.css b/style.css index d8f6743b..5ebfdb69 100644 --- a/style.css +++ b/style.css @@ -766,6 +766,11 @@ h3 { text-decoration: underline; } +.ui-dialog-aboutIITC { + max-width: 600px !important; + width: 600px !important; +} + td { padding: 0; vertical-align: top;