Skip to content

Commit 3ca5ca8

Browse files
committed
fix
1 parent 6d22efe commit 3ca5ca8

1 file changed

Lines changed: 30 additions & 20 deletions

File tree

JiandanHero/JiandanHero.user.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:en Jiandan Hero
44
// @name:zh-TW 煎蛋俠
55
// @namespace hoothin
6-
// @version 1.2
6+
// @version 1.3
77
// @description 为煎蛋jandan.net提供左右方向键快捷翻页、鼠标悬停显示大图、屏蔽指定用户发言等功能
88
// @description:en Tools for jandan.net
99
// @description:zh-TW 為煎蛋jandan.net提供左右方向鍵快捷翻頁、鼠標懸停顯示大圖、屏蔽指定用戶發言等功能
@@ -16,12 +16,14 @@
1616

1717
(function() {
1818
'use strict';
19-
var timer,getImgWH=function(img,callBack){
19+
var timer,tempImg=document.createElement("img"),getImgWH=function(img,callBack){
2020
if(timer)clearInterval(timer);
21+
tempImg.src=null;
22+
tempImg.src=img.src;
2123
var check=function(){
22-
if(img.width>0 || img.height>0){
24+
if(tempImg.width>0 || tempImg.height>0){
2325
if(timer)clearInterval(timer);
24-
callBack();
26+
callBack(tempImg.width,tempImg.height);
2527
return true;
2628
}else{
2729
return false;
@@ -96,17 +98,21 @@
9698
src=isHttps?src.replace(/http\:\/\//,"https://"):src.replace(/https\:\/\//,"http://");
9799
bigImg.src=img.src;
98100
bigImg.src=src;
101+
left=e.clientX;
102+
top=e.clientY;
99103
document.body.appendChild(bigImg);
100104
relocBigImg(left, top);
101-
getImgWH(bigImg,function(){
102-
relocBigImg(left, top);
105+
getImgWH(bigImg,function(w,h){
106+
relocBigImg(left, top, w, h);
103107
});
108+
bigImg.onload=function(){
109+
relocBigImg(left, top);
110+
};
104111
};
105112
img.onmouseout=function(e){
106113
document.body.removeChild(bigImg);
107114
bigImg.removeAttribute("height");
108115
bigImg.removeAttribute("width");
109-
bigImg.src=null;
110116
};
111117
img.onmousemove=function(e){
112118
left=e.clientX;
@@ -123,15 +129,17 @@
123129
bigImg.src=this.previousSibling.src;
124130
bigImg.src=src;
125131
document.body.appendChild(bigImg);
126-
getImgWH(bigImg,function(){
127-
relocBigImg(left, top);
132+
getImgWH(bigImg,function(w,h){
133+
relocBigImg(left, top, w, h);
128134
});
135+
bigImg.onload=function(){
136+
relocBigImg(left, top);
137+
};
129138
});
130139
$("p").on("mouseout","div.gif-mask",function(e){
131140
document.body.removeChild(bigImg);
132141
bigImg.removeAttribute("height");
133142
bigImg.removeAttribute("width");
134-
bigImg.src=null;
135143
});
136144
$("p").on("mousemove","div.gif-mask",function(e){
137145
left=e.clientX;
@@ -141,21 +149,23 @@
141149
}
142150
relocBigImg(left, top);
143151
});
144-
function relocBigImg(left, top){
145-
var type=bigImg.height/bigImg.width>document.documentElement.clientHeight/document.documentElement.clientWidth;
146-
if(type && bigImg.height>document.documentElement.clientHeight){
147-
bigImg.height=document.documentElement.clientHeight;
152+
function relocBigImg(left, top, w, h){
153+
var imgWidth=w?w:bigImg.width;
154+
var imgHeight=h?h:bigImg.height;
155+
var type=imgHeight/imgWidth>document.documentElement.clientHeight/document.documentElement.clientWidth;
156+
if(type && imgHeight>document.documentElement.clientHeight){
157+
imgHeight=document.documentElement.clientHeight;
148158
}
149-
if(!type && bigImg.width>document.documentElement.clientWidth){
150-
bigImg.width=document.documentElement.clientWidth;
159+
if(!type && imgWidth>document.documentElement.clientWidth){
160+
imgWidth=document.documentElement.clientWidth;
151161
}
152-
if(top-bigImg.height<0){
162+
if(top-imgHeight<0){
153163
top=0;
154164
}else{
155-
top-=bigImg.height;
165+
top-=imgHeight;
156166
}
157-
if(left+bigImg.width>document.documentElement.clientWidth){
158-
left=document.documentElement.clientWidth-bigImg.width;
167+
if(left+imgWidth>document.documentElement.clientWidth){
168+
left=document.documentElement.clientWidth-imgWidth;
159169
}
160170
bigImg.style.left=left+10+"px";
161171
bigImg.style.top=top+"px";

0 commit comments

Comments
 (0)