Created
August 31, 2010 13:31
-
-
Save erwan/559016 to your computer and use it in GitHub Desktop.
Chrome Screencast 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Global variable accessed by the popup | |
var telList; | |
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { | |
telList = request["phones"]; | |
chrome.pageAction.show(sender.tab.id); | |
sendResponse({}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var phoneRe = /^\s*((\d{2}\s?){5})\s*$/; | |
var texts = document.evaluate(".//text()[normalize-space(.)!='']", document.body, null, 6, null); | |
var phones = []; | |
for (var i = 0; i < texts.snapshotLength; i++) { | |
var textNode = texts.snapshotItem(i); | |
var text = textNode.textContent; | |
var m = phoneRe.exec(text); | |
if (m != null) { | |
var newText = document.createElement("a"); | |
newText.setAttribute("href", "callto:" + m[1]); | |
newText.appendChild(document.createTextNode(m[0])); | |
textNode.parentNode.replaceChild(newText, textNode); | |
phones.push(m[1]); | |
} | |
} | |
if (phones.length > 0) { | |
chrome.extension.sendRequest({"phones": phones}, function(response) {}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Telify", | |
"version": "0.2", | |
"description": "Click to call", | |
"background_page": "background.html", | |
"content_scripts": [{ | |
"js": ["contentScript.js"], | |
"matches": ["http://*/*"] | |
}], | |
"permissions": [ | |
"tabs", | |
"http://ajax.googleapis.com/" | |
], | |
"page_action": { | |
"default_icon": "icons/tel.gif", | |
"default_popup": "popup.html" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<style> | |
body { | |
width: 200px; | |
} | |
</style> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
<script> | |
$(document).ready(function(){ | |
var telList = chrome.extension.getBackgroundPage().telList; | |
if (telList && telList.length > 0) { | |
for (i in telList) | |
$("ul").append("<li><a href='callto:" + telList[i] + "'>" + telList[i] + "</a></li>"); | |
} | |
}); | |
</script> | |
<body> | |
<ul></ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment