// ==UserScript==
// @name Dodawacz Identyfikatorów
// @author Wasacz
// @version 1.0 beta
// @description Dododawanie identyfikatora wpisu na stronie głównej Jogger.pl
// @include http://jogger.pl/*
// ==/UserScript==

//window.addEventListener('DOMContentLoaded', function() {
	if (document.getElementById('frontpage')) {
		var divs = document.getElementsByTagName('div');
		var tip = 'Identyfikator wpisu';
		var i, entryid, a, p, date;
		for (i = 0; i < divs.length; i++) {
			if (divs[i].className.match(/(^|\s)entry(\s|$)/)) {
				entryid = divs[i].getAttribute('id').match(/[0-9]+$/);
				if (entryid) {			
					a = document.createElement('a');
					a.setAttribute('href', '#'+divs[i].getAttribute('id'));
					a.setAttribute('id', entryid);
					a.setAttribute('title', tip+': #'+entryid);
					a.style.marginLeft = '5px'; // /t/s/home.css
					a.addEventListener('click', function(e) {
						prompt(tip+':', '#'+this.getAttribute('id'));
						e.preventDefault();
					}, false);
					a.appendChild(document.createTextNode('#'+entryid));
					p = divs[i].getElementsByTagName('p')[0]	
					date = p.getElementsByTagName('span')[0];			
					p.insertBefore(a, date);
					p.insertBefore(document.createTextNode(' '), date);
				}
			}
		}
	}
//}, false);
