/*
* @title Tumblr dashboard bookmark
* @description Save your depth and restart digging
* @include http://www.tumblr.com/*
* @license Public Domain
*/
(function(){
var currentPosition = window.scrollY;
var currentPost;
var posts = document.querySelectorAll('#posts .post_container:not(.new_post_buttons_container):not(._bookmark)');
for(var i = 0; i < posts.length; i++){
if(jQuery(posts[i]).offset().top >= currentPosition){
currentPost = posts[i];
break;
}
}
var id = (parseInt(currentPost.querySelector(".post").id.replace("post_", ""), 10) + 1),
href = window.next_page.replace(/\d+$/, id),
now = new Date,
// next_page
// * http://www.tumblr.com/dashboard/2/12345 // initial
// * /dashboard/2/12345 // after autopaging
// * http://www.tumblr.com/tagged/bookmarklet?before=12345 // initial
// * /tagged/bookmarklet?before=12345 // after autopaging
label = window.next_page.replace("http://www.tumblr.com", "")
.replace(/\?before=\d+$|\d+\/\d+$/, "").slice(1)
+ " - " + [now.getFullYear(), now.getMonth(), now.getDate()].join("-"),
insertHTML =
'<li class="post_container _bookmark">' +
' <div class="post post_full">' +
' Bookmark: <a href="' + href + '">' + label + '</a>' +
' </div>' +
'</li>';
jQuery(insertHTML).insertBefore(currentPost).hide().slideDown();
})();