Skip to content

Instantly share code, notes, and snippets.

@webos-goodies
Created April 20, 2011 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webos-goodies/930513 to your computer and use it in GitHub Desktop.
Save webos-goodies/930513 to your computer and use it in GitHub Desktop.
UserJS to maximize image by double-click on Opera
// ==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