// @name Flickr // @desc Supports drag and drop upload of photos into Flickr // @url http://www.flickr.com/ // @include *.flickr.com/* SSB.contextMenu.add("Recent Activity (2 days)", "/recent_activity.gne?days=2"); SSB.contextMenu.add("Recent Activity (7 days)", "/recent_activity.gne?days=7"); SSB.contextMenu.add("Photos you've commented on", "/photos_comments.gne"); SSB.contextMenu.add("Photos from your contacts", "/photos/friends/"); SSB.contextMenu.add("Explore", "/explore/"); SSB.contextMenu.add("Organize", "/photos/organize"); SSB.contextMenu.add("Account", "/account/"); // tell people about the ability to drag and drop if (SSB.prefs.getValue('firstRun') == null) { SSB.prefs.setValue('firstRun', '1'); SSB.simpleNotify('Upload up to six pictures at a time by dragging them into the Flickr bubble', ''); } // add a drop handler to any flickr page SSB.dragDrop.ondrop = function() { // are we logged in ? if (typeof global_auth_hash == 'undefined' || global_auth_hash == 0) { SSB.simpleNotify( 'It looks like you\'re not logged-in to Flickr, please login in order to upload', "javascript:document.location.replace('http://www.flickr.com/signin/');"); return; } // prepare the form variables var formVars = { 'done' : '1', 'complex_perms' : '0', 'magic_cookie' : global_auth_hash, 'MAX_FILE_SIZE' : '31457280', 'is_public_0' : '1', 'tags' : '', 'Submit' : 'UPLOAD' }; var fileVars = ['file1', 'file2', 'file3', 'file4', 'file5', 'file6']; var postBody = SSB.dragDrop.getPostBody(formVars, fileVars); // show feedback to user (uploading...) bblsCreateModal(); bblsSetModalText('Uploading …'); var xmlhttp = getXHR(); xmlhttp.open('POST', 'http://www.flickr.com/photos_upload_process.gne'); xmlhttp.setRequestHeader('Content-Type', SSB.dragDrop.getContentType()); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { bbls_onLoad(xmlhttp.responseText); } } xmlhttp.send(postBody); } // this is just for creating a fancy 'uploading...' modal function bblsCreateModal() { // prepare ie bod = document.getElementsByTagName('body')[0]; bod.style.height = '100%'; bod.style.overflow = 'hidden'; htm = document.getElementsByTagName('html')[0]; htm.style.height = '100%'; htm.style.overflow = 'hidden'; // create the overlay bod = document.getElementsByTagName('body')[0]; overlay = document.createElement('div'); overlay.id = 'overlay'; overlay.style.cssText = "position:absolute; top:0px; left:0px; width:100%; height:100%; z-index:5000; background-color:#000; -moz-opacity: 0.8; opacity:.80; filter: alpha(opacity=80);text-align: center;"; bod.appendChild(overlay); // create the lightbox bod = document.getElementsByTagName('body')[0]; lb = document.createElement('div'); lb.id = 'bbls_lb'; lbPosX = (document.body.offsetWidth/2)-100; lbPosY = (document.body.offsetHeight/2)-50; lb.style.cssText = 'position: absolute; top:' + lbPosY + 'px; left:' + lbPosX + 'px; z-index:9999; width:200px; height:50px; margin:0; border:2px solid #fff; background:#FEFEFF; text-align:left; font: arial,sans-serif; font-size: 16pt;border:5px solid #000;text-align:center;padding:20px;'; lb_txt = document.createElement('text'); lb_txt.innerHTML = ''; lb_txt.id = 'bbls_lb_txt'; lb_img = document.createElement('img'); lb_img.src = 'http://www.3d3r.com/bubbles/images/preloader.gif'; lb_img.style.cssText = 'display:block;margin: 15px auto 0'; lb.appendChild(lb_txt); lb.appendChild(lb_img); bod.appendChild(lb); } function bblsSetModalText(txt) { document.getElementById('bbls_lb_txt').innerHTML = txt; } function getXHR() { var xmlhttp = false; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } return xmlhttp; } function bbls_onError() { SSB.simpleNotify('Photo upload failed.', ''); document.getElementById('bbls_overlay').removeNode(true); document.getElementById('bbls_lb').removeNode(true); //document.location.replace('http://www.flickr.com/photos'); } function bbls_onLoad(responseText) { // feedback to user (aftere uploading comes processing...) bblsSetModalText('Processing …'); // now we need to check if the image is ready on flickr // prepare a few variables, parse them out of the response flickr sent us var getRespVar = function(varName) { var x = responseText; var a = x.search("var " + varName + " = '"); var b = x.substring(a,x.length-a-1); var c = b.search("'")+1; var d = b.substring(c, b.length-c-1); var e = d.search("'"); var f = d.substring(0,e); SSB.prefs.setValue(varName, f); } getRespVar('tickets'); getRespVar('oks'); getRespVar('fails'); // we'd go with this but it gave JS errors //document.write(responseDetails.responseText); // check the status bbls_checkUploadStatus(); } function bbls_checkUploadStatus() { // check if the images are ready var qs = 'oks='+SSB.prefs.getValue('oks'); qs += '&fails='+SSB.prefs.getValue('fails'); qs += '&tickets='+SSB.prefs.getValue('tickets'); qs += '&cb='+(new Date().getTime()); var xmlhttp = getXHR(); xmlhttp.open('GET', 'http://flickr.com/photos_upload_rs_check.gne?'+qs); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { bbls_checkUploadOnLoad(xmlhttp.responseText); } } xmlhttp.send(null); } function bbls_checkUploadOnError(req) { bbls_uploadComplete(0); } function bbls_checkUploadOnLoad(responseText) { // we've got some sort of response, check what it means var A = responseText.split('|'); if (A.length != 3) { setTimeout('bbls_checkUploadStatus()', 750); return; } var tickets = A[0]; var ticketsA = tickets.split(','); var fails = A[2]; var oks = A[1]; if (tickets.length == 0) { bbls_uploadComplete(1); } else { SSB.prefs.setValue('tickets', tickets); SSB.prefs.setValue('fails', fails); SSB.prefs.setValue('oks', oks); setTimeout('bbls_checkUploadStatus()', 750); } } function bbls_uploadComplete(success) { // do some notifications if we were actually succesfull if (success) { var words = ['Funky', 'Helluluya', 'Eye Karamba', 'Wham', 'Sweet', 'Yeah', 'Yeeha']; var word = words[ Math.floor(words.length * (Math.random() % 1)) ]; SSB.simpleNotify(word+'!
Photos uploaded succesfully', ''); bblsSetModalText('Done'); } else { SSB.simpleNotify('Photo processing failed.', ''); } // go the user's photos page var userName = eval("document.getElementById('TopBar').childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[1].innerHTML"); var urlAdd = (typeof userName != 'undefined' && userName != 0) ? '/'+userName+'/' : ''; document.location.replace('http://www.flickr.com/photos'+urlAdd); }