Permalink
Browse files

Addes Cx

  • Loading branch information...
1 parent 6f77ea1 commit 4cc830d00a824399982d9874f005bee77f967c90 @brianstewart brianstewart committed Nov 9, 2011
Showing with 43 additions and 0 deletions.
  1. +1 −0 cloudsave.html
  2. +1 −0 cloudsave.js
  3. +41 −0 hosts/cx.js
View
@@ -55,3 +55,4 @@
<script src="hosts/twitrpix.js"></script>
<script src="hosts/imgly.js"></script>
<script src="hosts/droplr.js"></script>
+<script src="hosts/cx.js"></script>
View
@@ -31,6 +31,7 @@ var original = {
imgly: 'Imgly'
},
"all": {
+ cx: 'Cx',
box: 'Box.net',
sugarsync: 'SugarSync',
dropbox: 'Dropbox',
View
@@ -0,0 +1,41 @@
+// Cx
+
+Hosts.cx = function uploadCx(file, callback) {
+ var login_shown = false;
+ var poll = function(){
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", "https://www.cx.com/0/userInfo/viewProfile");
+ xhr.send();
+ xhr.onload = function(){
+ if (xhr.status==200) { // Logged in
+
+ var tmp = new XMLHttpRequest();
+ var abuf = 'responseType' in tmp && 'response' in tmp;
+ var binxhr = !!this.sendAsBinary;
+
+ // Amazon needs file size to upload
+ getURL(abuf?'arraybuffer':(binxhr?'binary':'raw'),file, function(file){
+
+ var xhr2 = new XMLHttpRequest();
+ xhr2.open("POST", "https://www.cx.com/0/filedata/upload");
+ xhr2.onload = function(){
+ callback({url:"http://www.cx.com/mycx/files"});
+ }
+ xhr2.sendMultipart({
+ fileName: file.name,
+ fileSize: file.data.byteLength,
+ file: file
+ });
+ });
+
+ } else {
+ if (!login_shown) {
+ chrome.tabs.create({url:"http://www.cx.com/mycx/sign_in"});
+ login_shown = true;
+ }
+ setTimeout(poll, 2000);
+ }
+ }
+ }
+ poll();
+}

0 comments on commit 4cc830d

Please sign in to comment.