Last active
March 8, 2017 13:38
-
-
Save asl97/f96314e965f861bead1d4bacb206b458 to your computer and use it in GitHub Desktop.
Tampermonkey Userscript for embedding image into KissAnime anime listing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name KissAnime Thumbnails List | |
// @version 0.0.2 | |
// @namespace https://gist.githubusercontent.com/asl97/ | |
// @downloadURL https://gist.githubusercontent.com/asl97/f96314e965f861bead1d4bacb206b458/raw/KissAnime%2520Thumbnails%2520List.user.js | |
// @description Embed thumbnails into anime list | |
// @author ASL97 | |
// @include http://kissanime.ru/Genre/* | |
// @include http://kissanime.ru/AnimeList* | |
// @grant none | |
// | |
// We need to run at start before tooltip get rid of our image | |
// Todo: find better way to make sure we ran before the tooltip | |
// @run-at document-body | |
// | |
// Using kissanime jquery script instead of latests > http://code.jquery.com/jquery-latest.min.js | |
// @require http://kissanime.ru/Scripts/jquery17.min.js | |
// | |
// Include the tooltip script to get it working again | |
// @require http://kissanime.ru/Scripts/jqueryTooltip.js | |
// | |
// ==/UserScript== | |
// Assume page is ready or else the tooltip script might get rid of our image before we get to it | |
//$(".listing").ready(function(){ | |
image = false; | |
$(".listing td[title]").each(function(index){ | |
parser = new DOMParser(); | |
doc = parser.parseFromString(this.title, "text/html"); | |
// Copy the title over to the image so we can use it later when creating the tooltip | |
img = $(new Image()).attr({"src":doc.images[0].src, "title":this.title}); | |
// Stop the website tooltip from creating the tooltip cause it doesn't take into account the height change due to embedding the image | |
$(this).removeAttr("title"); | |
$(this).before($("<td/>").append(img)); | |
// Create the tooltip ourselves after the image loads so we know how much to offset it | |
img.load(function() { | |
// The parent next should be the title since we inserted the image before it | |
that = $(this).parent().next(); | |
// Add back the title so we can create our tooltip | |
that.attr("title", this.title); | |
// Clean up | |
$(this).removeAttr("title"); | |
that.tooltip({ offset: [$(this).height(), 200], effect: 'slide', predelay: 300 }).dynamic({ bottom: { direction: 'down', bounce: true} }); | |
}); | |
image = true; | |
}); | |
// If we have added an image, we add an table header to fix the alignment | |
if(image){ | |
$(".head").prepend($("<th/>")); | |
} | |
//}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment