Created
June 22, 2015 22:39
-
-
Save DataKinds/6e1558f055b8d8412554 to your computer and use it in GitHub Desktop.
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 Uploadius Hover Zoom | |
// @namespace uploadiushoverzoom | |
// @include http://swololol.com/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
var title = document.getElementsByTagName("h1"); | |
title[0].innerHTML = "<a style=\"text-decoration:none;color:#00f;\" href=\"http://swololol.com/ufi\">Uploadius (hoverzoom by @aearnus)</a>" | |
var links = document.getElementsByTagName("a"); | |
var imageLinks = []; | |
for(var i = 0; i < links.length; i++) { | |
if(/\.(jpg|gif|png|jpeg)$/.test(links[i].href)) { | |
imageLinks.push(links[i]); | |
} | |
} | |
var documentHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight); | |
//http://stackoverflow.com/questions/1145850/how-to-get-height-of-entire-document-with-javascript | |
for(var i = 0; i < imageLinks.length; i++) { | |
var currentLink = imageLinks[i]; | |
currentLink.onmouseenter = function(cursorEvent) { | |
var x = cursorEvent.clientX; | |
var y = cursorEvent.clientY; | |
window.hoverImg = document.createElement("img"); | |
window.hoverImg.src = this.href; | |
if(documentHeight - y < 300) { | |
window.hoverImg.setAttribute("style", ("position: absolute; top:" + (y+document.body.scrollTop-250) + "px; left:" + (x+document.body.scrollLeft+5) + "px; width: auto; max-height: 250px")); | |
} else { | |
window.hoverImg.setAttribute("style", ("position: absolute; top:" + (y+document.body.scrollTop) + "px; left:" + (x+document.body.scrollLeft+5) + "px; width: auto; max-height: 250px")); | |
} | |
document.body.appendChild(window.hoverImg); | |
} | |
currentLink.onmouseleave = function() { | |
document.body.removeChild(window.hoverImg); | |
window.hoverImg = {}; | |
} | |
currentLink.onmouseout = function() { | |
document.body.removeChild(window.hoverImg); | |
window.hoverImg = {}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment