SmallImageZoom

Enables Maxthon4 to fit small image opened in a separate tab into the window or zoom back to its original size.

当前为 2014-10-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name SmallImageZoom
// @author ElDoRado1239
// @version 0.94
// @description Enables Maxthon4 to fit small image opened in a separate tab into the window or zoom back to its original size.
// @include *.jpg
// @include *.jpeg
// @include *.png
// @include *.gif
// @namespace https://greasyfork.org/users/6103
// ==/UserScript==

var img = document.getElementById('img_elem');
var drag = false;
var mdown = false;
var state = 0;
setTimeout(init,10);
function init(){
	if(img.naturalWidth == 0) setTimeout(init,10);
	else{
		if(img.naturalHeight >= window.innerHeight || img.naturalWidth >= window.innerWidth){
			img.onmousemove = undefined;
			img.onmouseup = undefined;
			img.onmousedown = undefined;
			return;
		}
		img.onmousedown = mouseDown;
		img.onmousemove = mouseMove;
		img.onmouseup = mouseUp;
		window.onresize = mouseUp;
		mouseUp('init');
	}
}
function mouseDown(e){
	if(e.which != 3) mdown = true;
}
function mouseMove(){
	if(mdown){
		drag = true;
		img.style.cursor = "all-scroll";
	}
}
function mouseUp(e){
	if(mdown==false && e!='init') return;
	mdown = false;
	switch(state){
		case 0:{
			if(drag){
				drag = false;
				img.style.cursor = "-webkit-zoom-in";	
				return;
			}
			if(img.naturalHeight>=img.naturalWidth){
				img.style.height = window.innerHeight;
				img.style.width = window.innerHeight*(img.naturalWidth/img.naturalHeight);
				img.style.left = ((window.innerWidth-parseInt(img.style.width))/2)+"px";
				img.style.top = "0px";
			}
			if(img.naturalWidth>img.naturalHeight){
				img.style.width = window.innerWidth;
				img.style.height = window.innerWidth*(img.naturalHeight/img.naturalWidth);
				img.style.left = "0px";
				img.style.top = ((window.innerHeight-parseInt(img.style.height))/2)+"px";
			}
			if(parseInt(img.style.width)>window.innerWidth){
				img.style.width = window.innerWidth;
				img.style.height = window.innerWidth*(img.naturalHeight/img.naturalWidth);
				img.style.left = "0px";
				img.style.top = ((window.innerHeight-parseInt(img.style.height))/2)+"px";
			}
			if(parseInt(img.style.height)>window.innerHeight){
				img.style.height = window.innerHeight;
				img.style.width = window.innerHeight*(img.naturalWidth/img.naturalHeight);
				img.style.left = ((window.innerWidth-parseInt(img.style.width))/2)+"px";
				img.style.top = "0px";
			}
			img.style.cursor = "-webkit-zoom-out";
			state++;
			return;
		}
		case 1:{
			if(drag){
				drag = false;
				img.style.cursor = "-webkit-zoom-out";
				return;
			}
			img.style.width = img.naturalWidth;
			img.style.height = img.naturalHeight;
			img.style.left = ((window.innerWidth-parseInt(img.style.width))/2)+"px";
			img.style.top = ((window.innerHeight-parseInt(img.style.height))/2)+"px";
			img.style.cursor = "-webkit-zoom-in";	
			state--;
			return;
		}
	}	
}