Created
June 22, 2015 22:27
-
-
Save DataKinds/29f9ea9efb320ad5622f to your computer and use it in GitHub Desktop.
This file contains hidden or 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== | |
window.onload = function() { | |
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.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.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