UserJS to maximize image by double-click on Opera
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== | |
// @description maximize image by double-click instead of auto resizing. | |
// @author Chihiro Ito | |
// ==/UserScript== | |
if(document.querySelector("head>link[rel='stylesheet'][href='opera:style/image.css']")) { | |
window.donotrun=true; | |
document.body.style='margin:0; padding:0;'; | |
var img = document.getElementsByTagName('img')[0]; | |
if(img) { | |
var prevTime = 0; | |
img.addEventListener('mousedown', function(e) { | |
var time = (new Date()).getTime(); | |
if(time - prevTime > 500) { | |
prevTime = time; | |
return; | |
} | |
prevTime = 0; | |
if((img.style.width && img.style.width != 'auto') || | |
(img.style.height && img.style.height != 'auto')) { | |
img.style.width = img.style.height = 'auto'; | |
} else { | |
var clientWidth = 0,clientHeight = 0; | |
if(window.innerWidth){ | |
clientWidth = window.innerWidth; | |
clientHeight = window.innerHeight; | |
} else if(document.documentElement && document.documentElement.clientWidth){ | |
clientWidth = document.documentElement.clientWidth; | |
clientHeight = document.documentElement.clientHeight; | |
} else if(document.body){ | |
clientWidth = document.body.clientWidth; | |
clientHeight = document.body.clientHeight; | |
} | |
var imageAspect = img.width / img.height; | |
var clientAspect = clientWidth / clientHeight; | |
if(imageAspect <= clientAspect) { | |
img.style.width = (clientHeight * imageAspect) + 'px'; | |
img.style.height = clientHeight + 'px'; | |
} else { | |
img.style.width = clientWidth + 'px'; | |
img.style.height = (clientWidth / imageAspect) + 'px'; | |
} | |
} | |
}, false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment