// ==UserScript==
// @name Kitty Kats - improve thumbnails
// @namespace http://kitty-kats.net/
// @version 0.2
// @description faster thumbnails load & display
// @author Croata7
// @match http://kitty-kats.net/*
// @require http://code.jquery.com/jquery-latest.min.js
// @require https://raw.githubusercontent.com/pie6k/jquery.initialize/master/jquery.initialize.min.js
// @grant none
// ==/UserScript==
$(document).ready(function() {
'use strict';
$.initialize(".tooltip", function() {
// width to 95%
$(this).css("width", "95%");
// height
$.initialize(".tooltip-content-inner", function() {
$(this).css("max-height", 300).css("overflow", "auto");
}, { target: this });
}, { target: document.body });
// change tooltip previewer to display only a few random (8) thumbnails
XF.PreviewTooltip.prototype.loaded = function (a, b) {
var c = null;
if (a.html) {
var od = document.implementation.createHTMLDocument('virtual');
c = $(a.html.content, od);
$('*:not(:has(*))', c).not("a, img").remove(); // remove leaf who isn't <a> nor <img>
var n = $("img", c).length;
while (n > 9) {
$("img:eq(" + (1 + Math.floor((n-1) * Math.random())) + ")", c).parent().remove();
n = $("img", c).length;
}
}
c && XF.setupHtmlInsert(c[0].innerHTML, function (x, d, e) { b(x) });
};
// trigger eager loading of thumbnails for every link
XF.Element.getHandlers('preview-tooltip').forEach( function(tt, i) {
tt.options.delay = 100;
tt.trigger.options.delayIn = 300;
tt.trigger.options.delayInLoading = 0;
tt.trigger.options.delayOut = 100;
setTimeout(function() { tt.trigger.focusEnter(); }, 1000 * i);
setTimeout(function() { tt.trigger.hide(); }, 1000 * i + 200);
});
});