Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Unified Diff: chrome/test/data/extensions/samples/mappy/mappy_content_script.js

Issue 160276: mole expand/collapse API (Closed)
Patch Set: fixed a couple of crashers Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/samples/mappy/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 0000000000000000000000000000000000000000..1b9f49c7ed1b8bd4ed04fdc0d1dc61a73b64d832
--- /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);
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698