summaryrefslogtreecommitdiffstats
path: root/chrome/test/data
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/test/data')
-rwxr-xr-xchrome/test/data/extensions/samples/mappy/manifest.json11
-rwxr-xr-xchrome/test/data/extensions/samples/mappy/mappy_content_script.js55
-rwxr-xr-xchrome/test/data/extensions/samples/mappy/mappy_toolstrip.html68
3 files changed, 134 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/samples/mappy/manifest.json b/chrome/test/data/extensions/samples/mappy/manifest.json
new file mode 100755
index 0000000..1473ce8
--- /dev/null
+++ b/chrome/test/data/extensions/samples/mappy/manifest.json
@@ -0,0 +1,11 @@
+{
+ "name": "Mappy",
+ "version": "0.2",
+ "description": "Map stuff",
+ "toolstrips": [
+ "mappy_toolstrip.html"
+ ],
+ "content_scripts": [
+ { "matches": ["http://*/*"], "js": ["mappy_content_script.js"] }
+ ]
+}
diff --git a/chrome/test/data/extensions/samples/mappy/mappy_content_script.js b/chrome/test/data/extensions/samples/mappy/mappy_content_script.js
new file mode 100755
index 0000000..1b9f49c
--- /dev/null
+++ b/chrome/test/data/extensions/samples/mappy/mappy_content_script.js
@@ -0,0 +1,55 @@
+// find map on demand
+
+console.log("mappy_content_script.js loaded");
+
+var maps_key = "ABQIAAAATfHumDbW3OmRByfquHd3SRTRERdeAiwZ9EeJWta3L_JZVS0bOBRQeZgr4K0xyVKzUdnnuFl8X9PX0w";
+
+chrome.extension.onConnect.addListener(function(port) {
+ //console.log("extension connected");
+ port.onMessage.addListener(function(data) {
+ //console.log("extension sent message");
+ findAddress(port);
+ });
+});
+
+var findAddress = function(port) {
+ var found;
+ var re = /(\d+ [':.,\s\w]*,\s*[A-Za-z]+\s*\d{5}(-\d{4})?)/m;
+ var node = document.body;
+ var done = false;
+ while (!done) {
+ done = true;
+ for (var i = 0; i < node.childNodes.length; ++i) {
+ var child = node.childNodes[i];
+ if (child.textContent.match(re)) {
+ node = child;
+ found = node;
+ done = false;
+ break;
+ }
+ }
+ }
+ if (found) {
+ var text = "";
+ if (found.childNodes.length) {
+ for (var i = 0; i < found.childNodes.length; ++i) {
+ text += found.childNodes[i].textContent + " ";
+ }
+ } else {
+ text = found.textContent;
+ }
+ var match = re.exec(text);
+ if (match && match.length) {
+ console.log("found: " + match[0]);
+ var trim = /\s{2,}/g;
+ var map = match[0].replace(trim, " ");
+ port.postMessage({message:"map", values:[map]});
+ } else {
+ console.log("found bad " + found.textContent);
+ console.log("no match in: " + text);
+ }
+ } else {
+ console.log("no match in " + node.textContent);
+ }
+}
+
diff --git a/chrome/test/data/extensions/samples/mappy/mappy_toolstrip.html b/chrome/test/data/extensions/samples/mappy/mappy_toolstrip.html
new file mode 100755
index 0000000..d279a15
--- /dev/null
+++ b/chrome/test/data/extensions/samples/mappy/mappy_toolstrip.html
@@ -0,0 +1,68 @@
+<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAATfHumDbW3OmRByfquHd3SRTRERdeAiwZ9EeJWta3L_JZVS0bOBRQeZgr4K0xyVKzUdnnuFl8X9PX0w&sensor=false"
+ type="text/javascript"></script>
+<script>
+var maps_key = "ABQIAAAATfHumDbW3OmRByfquHd3SRTRERdeAiwZ9EeJWta3L_JZVS0bOBRQeZgr4K0xyVKzUdnnuFl8X9PX0w";
+
+function xhr_geocode(address) {
+ var xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4 && xhr.status == 200) {
+ console.log(xhr.responseText);
+ var parsed = JSON.parse(xhr.responseText);
+ console.dir(parsed);
+ var point = parsed.Placemark[0].Point.coordinates;
+ var latlng = point[1] + "," + point[0];
+ window.open("http://maps.google.com/staticmap?center=" + latlng +
+ "&markers=" + latlng + "&zoom=14" +
+ "&size=512x512&sensor=false&key=" + maps_key,
+ "mappy_popup",
+ "width=512,height=512");
+ } else {
+ console.log("xhr: " + xhr.readyState);
+ }
+ };
+ var url =
+ "http://maps.google.com/maps/geo?output=json&oe=utf8&sensor=false&key=" +
+ maps_key + "&q=" + address;
+ console.log(url);
+ xhr.open("GET", url);
+ xhr.send(null);
+}
+
+function gclient_geocode(address) {
+ var geocoder = new GClientGeocoder();
+ geocoder.getLatLng(address, function(point) {
+ if (!point) {
+ console.log(address + " not found");
+ } else {
+ var latlng = point.toUrlValue();
+ var url = "http://maps.google.com/staticmap?center=" + latlng +
+ "&markers=" + latlng + "&zoom=14" +
+ "&size=512x512&sensor=false&key=" + maps_key;
+ //window.open(url, "mappy_popup", "width=512,height=512");
+ document.body.style.width = "512px";
+ setTimeout(chrome.toolstrip.expand, 100, 512, url);
+ }
+ });
+}
+
+function map() {
+ chrome.tabs.getSelected(null, function(tab) {
+ var port = chrome.tabs.connect(tab.id);
+ if (!port) {
+ console.log("no port");
+ } else {
+ port.onMessage.addListener(function(data) {
+ var address = data.values[0];
+ //xhr_geocode(address);
+ gclient_geocode(address);
+ });
+ port.postMessage({message: "hello tab: " + tab.id});
+ console.log("sent message");
+ }
+ });
+};
+</script>
+<div class="toolstrip-button" onclick="map()">
+<span>Mappy</span>
+</div>