// @name Google Docs uploader // @desc Google Docs uploader // @url http://docs.google.com/ // @include *.google.*/* // gdocs upload API: http://code.google.com/apis/documents/developers_guide_protocol.html#UploadingDocs // todo: try/catch some of the assumptions on incoming data // anonymous function that wraps whole script to prevent naming conflicts new function() { // check minimum version, the parseInt trick is to handle a bug in versions prior // to 1.92c that would return an integer rather than a string for the version if (SSB.version < '1.93' || parseInt(SSB.version)==SSB.version) { SSB.simpleNotify('To use this extension you will have to get the latest Bubbles', 'http://www.bubbleshq.com/download'); return; } // handler for dropped files SSB.dragDrop.ondrop = function() { // fetch the gdocs auth cookie var cookies = document.cookie.split(';'); var cookiesMap = {}; for (var i=0; i', '
Uploading...
', '
', '$FILENAME', '

', '
', '
', '
 
', '
', '
', '
', ''].join('').replace('$FILENAME', cleanFileName), 200, 92, 3, false); var xhr = SSB.getXHR(); xhr.open('POST', 'http://docs.google.com/feeds/documents/private/full'); xhr.setRequestHeader('Content-Type', contentType); xhr.setRequestHeader('Authorization', authToken); xhr.setRequestHeader('slug', cleanFileName); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { // see if we got success if (xhr.status == 201) { notif.document.getElementById('status').innerHTML = 'Upload Successfull'; // parse response var d = new ActiveXObject("MSXML.DomDocument"); d.loadXML(xhr.responseText); var node = d.selectSingleNode('/entry/link[@rel="alternate"]'); var url = node.attributes.getNamedItem('href').value; document.location.replace(url); } else { notif.document.getElementById('status').innerHTML = 'Upload Failed'; } notif.eval("SSB.notification.closeIn(2)"); } } xhr.onprogress = function(progress) { var p = notif.document.getElementById('progressbar'); if (!p) return; p.style.width = progress + '%'; if (progress == 100) { notif.document.getElementById('status').innerHTML = 'processing... '; } // make sure we're up for at least another 15 seconds (in case of slow upload or processing) notif.eval("SSB.notification.closeIn(15)"); } xhr.send(fileData); } }