Skip to content

Instantly share code, notes, and snippets.

@wuhx
Created May 8, 2012 05:26
Show Gist options
  • Save wuhx/2632780 to your computer and use it in GitHub Desktop.
Save wuhx/2632780 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name 500px graber
// @namespace http://500px.com/
// @description grab photo exif info
// @include http://500px.com/*
// @copyright 2012+, You
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// the guts of this userscript
function main() {
page_source = window.location;
photo_source = $('#thephoto a img').attr('src');
model = $('#photo-information li.camera strong').text();
focal_length = $('#photo-information li.focal-length strong').text().slice(0, -2);
shutter_speed = $('#photo-information li.shutter-speed strong').text().slice(0, -4);
aperture = $('#photo-information li.aperture strong').text().slice(2);
iso = $('#photo-information li.iso strong').text();
lens = $('#photo-information li.lens strong').text();
$('#sidebar').prepend('<a class="button" style="display:inline-block; margin-bottom:20px" href="http://wuditoo.com/photo/upload?page_source='+page_source+'&photo_source='+photo_source+'&model='+model+'&focal_length='+focal_length+'&shutter_speed='+shutter_speed+'&aperture='+aperture+'&iso='+iso+'&lens='+lens+'">grab it</a>');
}
// load jQuery and execute the main function
addJQuery(main);
// ==UserScript==
// @name flickr graber
// @namespace http://www.flickr.com/
// @description grab photo exif info
// @include http://www.flickr.com/*
// @copyright 2012+, You
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// the guts of this userscript
function main() {
page_source = window.location.href;
photo_source = '';
if($('#share-options-embed-textarea-l-bbcode').text().match(/\[img\](.*)\[\/img\]/)) {
photo_source = $('#share-options-embed-textarea-l-bbcode').text().match(/\[img\](.*)\[\/img\]/)[1];
} else {
photo_id = page_source.split('/')[5];
$.getJSON('http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=44f0e57ea2387f8f6d0c20e658ab3b88&photo_id='+photo_id+'&format=json&nojsoncallback=1', function(data){
$.each(data.sizes.size, function(key, val){
if (val.label == 'Large') {
photo_source = val.source;
return false;
}
if (val.label == 'Medium 640') {
photo_source = val.source;
}
});
origin_href = $('#graber').attr('href')
$('#graber').attr('href', origin_href+'&photo_source='+photo_source);
})
}
model = '';
focal_length = '';
shutter_speed = '';
aperture = '';
iso = '';
lens = '';
$meta_link = $('#options-menu .option-meta');
if($meta_link.length) {
meta_link = $meta_link.attr('href');
$('#sidebar').append('<div id="exif" style="display:none"></div>');
$('#exif').load(meta_link + ' .photo-data', function(){
model = $('#exif th:contains("Camera")').parent().find('td a').text();
shutter_speed = $('#exif th:contains("Exposure")').parent().find('td').eq(0).text().split('(');
if (shutter_speed.length > 1) {
shutter_speed = shutter_speed[1].slice(0, -1);
} else {
shutter_speed = shutter_speed[0].split(' ')[0];
}
aperture = $('#exif th:contains("Aperture")').parent().find('td').eq(0).text().slice(2);
focal_length = $('#exif th:contains("Focal Length")').parent().find('td').eq(0).text().slice(0, -3);
iso = $('#exif th:contains("ISO Speed")').parent().find('td').eq(0).text();
lens = $('#exif th:contains("Lens")').eq(0).parent().find('td').eq(0).text();
$('#sidebar').prepend('<a class="button" style="display:inline-block; margin-bottom:20px" href="http://wuditoo.com/photo/upload?page_source='+page_source+'&photo_source='+photo_source+'&model='+model+'&focal_length='+focal_length+'&shutter_speed='+shutter_speed+'&aperture='+aperture+'&iso='+iso+'&lens='+lens+'">grab it</a>');
})
} else {
$('#sidebar').prepend('<a id="graber" class="button" style="display:inline-block; margin-bottom:20px" href="http://wuditoo.com/photo/upload?page_source='+page_source+'&photo_source='+photo_source+'&model='+model+'&focal_length='+focal_length+'&shutter_speed='+shutter_speed+'&aperture='+aperture+'&iso='+iso+'&lens='+lens+'">grab it</a>');
}
}
// load jQuery and execute the main function
addJQuery(main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment