Permalink
Browse files

First release.

  • Loading branch information...
tonycosentini committed Jun 11, 2010
1 parent f27ac42 commit 2e8cf97fc9bd61d0d753e2b78f75594ef10dbf27
@@ -5,7 +5,7 @@
<key>Author</key>
<string>Tony Cosentini</string>
<key>CFBundleDisplayName</key>
<string>Send To Android</string>
<string>SendToAndroid</string>
<key>CFBundleIdentifier</key>
<string>com.tonycosentini.sendtoandroid</string>
<key>CFBundleInfoDictionaryVersion</key>
@@ -37,8 +37,15 @@
<key>Content</key>
<dict>
<key>Scripts</key>
<dict/>
<dict>
<key>End</key>
<array>
<string>content.js</string>
</array>
</dict>
</dict>
<key>Description</key>
<string>Null</string>
<key>ExtensionInfoDictionaryVersion</key>
<string>1.0</string>
<key>Permissions</key>
@@ -51,5 +58,7 @@
<string>All</string>
</dict>
</dict>
<key>Website</key>
<string>http://github.com/tonycosentini/Send-to-Android</string>
</dict>
</plist>
@@ -0,0 +1,33 @@
safari.self.addEventListener("message", handleMessage, false);
function handleMessage(msgEvent) {
if (msgEvent.name == "send") {
send();
} else if (msgEvent.name == "completed") {
showcompleted();
} else if (msgEvent.name == "error") {
showerror();
}
};
function send() {
var newdiv = document.createElement('div');
newdiv.setAttribute("id", "send-to-android-box");
newdiv.setAttribute("style", "width: 200px; background: #FFFFFF; color: #000000; position: fixed; top: 10px; left: 10px; font-size: 14px; border: 3px solid #000000; font-weight: bold; padding: 6px; -webkit-border-radius: 5px;");
newdiv.innerText = 'Sending to phone...';
var body = document.getElementsByTagName('body')[0];
body.appendChild(newdiv);
};
function showcompleted() {
var div = document.getElementById("send-to-android-box");
div.innerText= "Sent!";
// Probably a better way to do this timer stuff... but it's open source!
setTimeout("var div = document.getElementById('send-to-android-box'); var body = document.getElementsByTagName('body')[0]; body.removeChild(div);", 2500);
};
function showerror() {
var div = document.getElementById("send-to-android-box");
div.innerText= "Error :(";
setTimeout("var div = document.getElementById('send-to-android-box'); var body = document.getElementsByTagName('body')[0]; body.removeChild(div);", 2500);
};
@@ -9,11 +9,10 @@
function performCommand(event)
{
alert("perform!")
if (event.command !== "send")
return;
sendToPhone(event.target.browserWindow.activeTab.title, event.target.browserWindow.activeTab.url, null);
sendToPhone(event, event.target.browserWindow.activeTab.title, event.target.browserWindow.activeTab.url, null);
}
function validateCommand(event)
@@ -26,21 +25,7 @@
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) {
function sendToPhone(event, title, url, selection) {
var sendUrl = baseUrl + '?title=' + encodeURIComponent(title) +
'&url=' + encodeURIComponent(url) + '&sel=' + encodeURIComponent(selection);
req.open('GET', sendUrl, true);
@@ -52,13 +37,17 @@
element.style = "float:right; color:red";
element.textContent = "Waiting...";
theBody.insertBefore(element, theBody.firstChild);
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("send");
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');
// event.target.browserWindow.activeTab.getElementById('tag-id').innerHTML = '<ol><li>html data</li></ol>';
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("completed");
} else {
// most likely login, handle in new tab
//document.getElementById('msg').innerHTML =
@@ -67,8 +56,9 @@
var newTab = safari.application.openBrowserWindow().activeTab;
newTab.url = sendUrl;
}
} else {
} else {
alert(req.responseText);
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("error");
// document.getElementById('msg').innerHTML =
// chrome.i18n.getMessage('error_sending_message', req.responseText);
}
Binary file not shown.

This file was deleted.

Oops, something went wrong.

0 comments on commit 2e8cf97

Please sign in to comment.