joseadrian / Imgur: Image position on album

// ==UserScript==
// @name       Imgur: Image position on album
// @namespace  https://github.com/joseadrian
// @version    0.1
// @match      http://imgur.com/gallery/*
// @copyright  2014, Joseadrian Ochoa
// @require    //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// ==/UserScript==

// All gallery content is placed in this container. Just caching.
var images = $('#image').children('.album-image');
var template = '<div style="padding:5px;position:absolute;top:0;left:0;background-color:#000;color:#fff;cursor:pointer;" class="image-number">{{number}}</div>';

// To save some time?
var comments_box = $('#caption_textarea');

// Check if it is an album
if(images.length > 0)
{
    // Loop album images to get the their positions
    images.each(function() {
        var elem = $(this).css('position', 'relative');
        elem.append(template.replace('{{number}}', elem.attr('id')));
    });

    // Place the number of the image on the comments box when clicked
    images.delegate('.image-number', 'click', function() {
        comments_box.val('#' + $(this).text()).focus();
    });
}