Permalink
Browse files

first commit

  • Loading branch information...
tonycosentini committed Jun 8, 2010
0 parents commit f27ac4202dd566f9adf73d24502ed0a260ccbf85
0 README
No changes.
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Author</key>
<string>Tony Cosentini</string>
<key>CFBundleDisplayName</key>
<string>Send To Android</string>
<key>CFBundleIdentifier</key>
<string>com.tonycosentini.sendtoandroid</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>Chrome</key>
<dict>
<key>Global Page</key>
<string>global.html</string>
<key>Toolbar Items</key>
<array>
<dict>
<key>Command</key>
<string>send</string>
<key>Identifier</key>
<string>com.tonycosentini.androidbutton</string>
<key>Image</key>
<string>icon_19.png</string>
<key>Label</key>
<string>Send to Android</string>
<key>Tool Tip</key>
<string>Send this page to your Android device</string>
</dict>
</array>
</dict>
<key>Content</key>
<dict>
<key>Scripts</key>
<dict/>
</dict>
<key>ExtensionInfoDictionaryVersion</key>
<string>1.0</string>
<key>Permissions</key>
<dict>
<key>Website Access</key>
<dict>
<key>Include Secure Pages</key>
<true/>
<key>Level</key>
<string>All</string>
</dict>
</dict>
</dict>
</plist>
@@ -0,0 +1,93 @@
<!DOCTYPE HTML>
<script>
// Register for the validate and command events.
safari.application.addEventListener("command", performCommand, false);
safari.application.addEventListener("validate", validateCommand, false);
var baseUrl = 'http://chrometophone.appspot.com/send';
var req = new XMLHttpRequest();
function performCommand(event)
{
alert("perform!")
if (event.command !== "send")
return;
sendToPhone(event.target.browserWindow.activeTab.title, event.target.browserWindow.activeTab.url, null);
}
function validateCommand(event)
{
// You should always check the command.
if (event.command !== "send")
return;
// Disable the target if the current tab has no URL.
event.target.disabled = !event.target.browserWindow.activeTab.url;
}
function loadHandler() {
// document.getElementById('msg').innerHTML = chrome.i18n.getMessage('sending_message');
// document.getElementById('about').innerHTML = chrome.i18n.getMessage('about_message');
// chrome.tabs.getSelected(null, function(tab) {
// if (tab.url.indexOf('http:') == 0 ||
// tab.url.indexOf('https:') == 0) {
// chrome.tabs.executeScript(null, {file: "content_script.js"});
// } else {
// document.getElementById('msg').innerHTML = chrome.i18n.getMessage('invalid_scheme_message');
// }
// });
}
function sendToPhone(title, url, selection) {
var sendUrl = baseUrl + '?title=' + encodeURIComponent(title) +
'&url=' + encodeURIComponent(url) + '&sel=' + encodeURIComponent(selection);
req.open('GET', sendUrl, true);
req.setRequestHeader('X-Extension', 'true'); // XSRF protector
var theBody = document.body;
var element = document.createElement("p");
element.id = "status";
element.style = "float:right; color:red";
element.textContent = "Waiting...";
theBody.insertBefore(element, theBody.firstChild);
req.onreadystatechange = function() {
if (this.readyState == 4) {
if (req.status == 200) {
if (req.responseText.substring(0, 2) == 'OK') {
//TODO: Figure out message stuff.
// document.getElementById('msg').innerHTML = chrome.i18n.getMessage('sent_message');
} else {
// most likely login, handle in new tab
//document.getElementById('msg').innerHTML =
// chrome.i18n.getMessage('login_required_message');
// chrome.tabs.create({url: sendUrl});
var newTab = safari.application.openBrowserWindow().activeTab;
newTab.url = sendUrl;
}
} else {
alert(req.responseText);
// document.getElementById('msg').innerHTML =
// chrome.i18n.getMessage('error_sending_message', req.responseText);
}
}
}
req.send(null);
}
// chrome.extension.onConnect.addListener(function(port) {
// var tab = port.sender.tab;
// // This will get called by the content script. We go through
// // these hoops to get the optional text selection.
// port.onMessage.addListener(function(info) {
// var max_length = 256;
// if (info.selection.length > max_length) {
// info.selection = info.selection.substring(0, max_length);
// }
// sendToPhone(info.title, tab.url, info.selection);
// });
// });
</script>
Binary file not shown.
@@ -0,0 +1,63 @@
var baseUrl = 'http://chrometophone.appspot.com/send';
var req = new XMLHttpRequest();
alert("test");
function performCommand(event)
{
event.target.browserWindow.activeTab.url = currentURL;
alert(event.command);
}
function loadHandler() {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('sending_message');
document.getElementById('about').innerHTML = chrome.i18n.getMessage('about_message');
chrome.tabs.getSelected(null, function(tab) {
if (tab.url.indexOf('http:') == 0 ||
tab.url.indexOf('https:') == 0) {
chrome.tabs.executeScript(null, {file: "content_script.js"});
} else {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('invalid_scheme_message');
}
});
}
function sendToPhone(title, url, selection) {
var sendUrl = baseUrl + '?title=' + encodeURIComponent(title) +
'&url=' + encodeURIComponent(url) + '&sel=' + encodeURIComponent(selection);
req.open('GET', sendUrl, true);
req.setRequestHeader('X-Extension', 'true'); // XSRF protector
req.onreadystatechange = function() {
if (this.readyState == 4) {
if (req.status == 200) {
if (req.responseText.substring(0, 2) == 'OK') {
document.getElementById('msg').innerHTML = chrome.i18n.getMessage('sent_message');
} else { // most likely login, handle in new tab
document.getElementById('msg').innerHTML =
chrome.i18n.getMessage('login_required_message');
chrome.tabs.create({url: sendUrl});
}
} else {
document.getElementById('msg').innerHTML =
chrome.i18n.getMessage('error_sending_message', req.responseText);
}
}
}
req.send(null);
}
chrome.extension.onConnect.addListener(function(port) {
var tab = port.sender.tab;
// This will get called by the content script. We go through
// these hoops to get the optional text selection.
port.onMessage.addListener(function(info) {
var max_length = 256;
if (info.selection.length > max_length) {
info.selection = info.selection.substring(0, max_length);
}
sendToPhone(info.title, tab.url, info.selection);
});
});

0 comments on commit f27ac42

Please sign in to comment.