Skip to content

Instantly share code, notes, and snippets.

@mieky
Last active Dec 20, 2015
Embed
What would you like to do?
Bookmarklet to conveniently browse Isyyspakkaus in-line with just the left/right arrow keys.
;(function($) {
var url = 'http://www.lily.fi/blogit/isyyspakkaus';
if (window.location.href !== url) {
window.location = url;
return;
}
var links = $(".blog-archive-list").find("a").get().reverse();
var currentIndex = parseInt(localStorage.getItem("currentIndex") || 0, 10);
var maxIndex = links.length - 1;
function load(idx) {
$.get(links[idx].href, function(a, b, c) {
$(".content-container").empty().html(
$(a).find(".content-container").html()
);
jQuery(".content-container").find("img.lazy").each(function(i, item) {
item.src = item.getAttribute("data-original");
$(item).removeClass("lazy");
});
$(".social-controls").remove();
});
}
function update(idx) {
scrollTo(0, $(".blog-post-title").offset().top);
load(currentIndex);
document.title = (currentIndex + 1 + " / " + (maxIndex + 1));
localStorage.setItem("currentIndex", currentIndex);
}
$(document).keydown(function(e) {
var lastIndex = currentIndex;
if (e.keyCode === 37) {
currentIndex = Math.max(0, --currentIndex);
} else if (e.keyCode === 39) {
currentIndex = Math.min(links.length, ++currentIndex);
}
if (lastIndex !== currentIndex) {
update(currentIndex);
}
});
update(currentIndex);
alert('Voit nyt selata juttuja eteen- ja taaksepäin vasemmalla ja oikealla nuolinäppäimellä.');
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment