Danbooru hover preview

hover over pics to preview them à la 4chan X

Ajankohdalta 3.5.2020. Katso uusin versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Danbooru hover preview
// @namespace   makamys
// @description hover over pics to preview them à la 4chan X
// @match       *://*.donmai.us/*
// @version     1
// @grant       none
// ==/UserScript==

// from http://greasemonkey.win-start.de/patterns/add-css.html
function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

addGlobalStyle(`
#ihover {
  position: fixed;
  max-height: 100%;
  z-index: 1000;
  pointer-events: none;
}
`);
$(document).ready(function(){
  let ihover = null;
  let thumbs = $("article img");
  
  $("body").prepend(`
<div id="hoverUI"></div>
`);
  
  thumbs.mouseenter(function(event){
    $("#hoverUI").append(`<img id="ihover"></img>`);
    ihover = $("#ihover");
    
    let article = $(this).closest("article");
    ihover.attr("src", article.attr("data-large-file-url"));
  });
  
  thumbs.mouseleave(function(event){
    $("#hoverUI").empty();
  });
  
//TODO
//  thumbs.mousemove(function(event){
//    console.log(ihover.width());
//  
//    let x = event.pageX + (event.pageX > $(window).width() / 2 ? -0 : 0);
//  
//    ihover.css({left: x});
//  });
});