Permalink
Browse files

refined regex and fixed innerHTML

  • Loading branch information...
1 parent db7eccb commit 55b762ddaf7e358166d4b4c0cb57b0225ec010c7 @chrismatthieu committed May 6, 2011
Showing with 14 additions and 5 deletions.
  1. +13 −4 contentscript.js
  2. +1 −1 manifest.json
View
@@ -1,30 +1,39 @@
-var regex = /[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}/g;
+// var regex = /[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}/g;
+// var regex = /1?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}/g;
+// var regex = /[>\s]1?[- \.]?\(?[2-9]\d{2}\)?[- \.]?\d{3}[- \.]?\d{4}[<\s]/g;
+// var regex = /[>\s]1?[- \.]?\(?[2-9]\d{2}\)?[- \.]?\d{3}[- \.]?\d{4}/g;
+var regex = /[\s]1?[- \.]?\(?[2-9]\d{2}\)?[- \.]?\d{3}[- \.]?\d{4}/g;
var page;
var hits;
// Test the text of the body element against our regular expression.
if (regex.test(document.body.innerText)) {
// The regular expression produced a match, so notify the background page.
- page = document.body.innerText;
+ // page = document.body.innerHTML;
+ page = document.documentElement.innerHTML;
- hits = page.match(regex)
+ hits = page.match(regex);
for (var i = 0; i < hits.length; i += 1) {
// page = page.replace(hits[i], '<a href="http://phonophone.heroku.com?phone=' + trimString(hits[i]) + '">' + hits[i] + '</a>');
page = page.replace(hits[i], '<a href="#" onclick="javascript:window.open(\'http://phonophone.heroku.com?phone=' + trimString(hits[i]) + '\' , \'popup_id\', \'scrollbars,resizable,width=350,height=400\')">' + hits[i] + '</a>');
+ console.log('found: ' + trimString(hits[i]))
}
+ document.write (document.doctype);
document.write (page);
chrome.extension.sendRequest({}, function(response) {});
} else {
// No match was found.
+ console.log('no matches')
}
//To trim leading or trailing spaces
function trimString (str) {
- return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
+ // return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
+ return str.replace(/\s+/g, '').replace(/\(/g, '').replace(/\)/g, '').replace(/\./g, '').replace(/\-/g, '');
}
View
@@ -1,7 +1,7 @@
{
"name" : "Phono",
"version" : "0.1.0",
- "description" : "PhonoPhone",
+ "description" : "Phono is a browser-based webphone by Voxeo. More info available at http://phono.com",
"background_page" : "background.html",
"browser_action" : {
"default_icon" : "logo-32.png"

0 comments on commit 55b762d

Please sign in to comment.