Skip to content

Instantly share code, notes, and snippets.

@hotchpotch
Created May 29, 2010 05:32
Show Gist options
  • Save hotchpotch/418062 to your computer and use it in GitHub Desktop.
Save hotchpotch/418062 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Firefox to Phone
// @namespace http://rails2u.com/
// @description Send to Android phone
// @include http://*
// @include https://*
// ==/UserScript==
/*
* Original code by http://code.google.com/p/chrometophone/
* License: Apache License 2.0
*
* ReLogin url is https://www.google.com/accounts/ServiceLoginAuth?service=ah&sig=d71ef8b8d6150b23958ad03b3bf546b7
*/
var baseURL = 'http://chrometophone.appspot.com/send';
GM_registerMenuCommand("Send to Phone", menuSendToPhone);
function serialize(hash) {
var res = [];
for (var key in hash) {
res.push(encodeURIComponent(key) + '=' + encodeURIComponent(hash[key]));
}
return res.join('&');
}
function menuSendToPhone() {
var options = {
title: document.title,
url: location.href,
sel: window.getSelection().toString()
};
var requestURL = baseURL + '?' + serialize(options);
sendToPhone(requestURL);
}
function sendToPhone(requestURL) {
GM_xmlhttpRequest({
method: "GET",
url: requestURL,
headers: {
'X-Extension': 'true'
},
onload: function(res) {
if (res.responseText.substring(0, 2) == 'OK') {
GM_log('Send to phone: ' + options.toSource());
} else {
alert('Please login first.');
GM_openInTab(requestURL, '_blank');
}
},
onerror: function(res) {
alert('Send to phone error...');
GM_log('Send to phone error: ' + res.toSource());
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment