|
3 | 3 | // @name:en Jiandan Hero |
4 | 4 | // @name:zh-TW 煎蛋俠 |
5 | 5 | // @namespace hoothin |
6 | | -// @version 1.2 |
| 6 | +// @version 1.3 |
7 | 7 | // @description 为煎蛋jandan.net提供左右方向键快捷翻页、鼠标悬停显示大图、屏蔽指定用户发言等功能 |
8 | 8 | // @description:en Tools for jandan.net |
9 | 9 | // @description:zh-TW 為煎蛋jandan.net提供左右方向鍵快捷翻頁、鼠標懸停顯示大圖、屏蔽指定用戶發言等功能 |
|
16 | 16 |
|
17 | 17 | (function() { |
18 | 18 | 'use strict'; |
19 | | - var timer,getImgWH=function(img,callBack){ |
| 19 | + var timer,tempImg=document.createElement("img"),getImgWH=function(img,callBack){ |
20 | 20 | if(timer)clearInterval(timer); |
| 21 | + tempImg.src=null; |
| 22 | + tempImg.src=img.src; |
21 | 23 | var check=function(){ |
22 | | - if(img.width>0 || img.height>0){ |
| 24 | + if(tempImg.width>0 || tempImg.height>0){ |
23 | 25 | if(timer)clearInterval(timer); |
24 | | - callBack(); |
| 26 | + callBack(tempImg.width,tempImg.height); |
25 | 27 | return true; |
26 | 28 | }else{ |
27 | 29 | return false; |
|
96 | 98 | src=isHttps?src.replace(/http\:\/\//,"https://"):src.replace(/https\:\/\//,"http://"); |
97 | 99 | bigImg.src=img.src; |
98 | 100 | bigImg.src=src; |
| 101 | + left=e.clientX; |
| 102 | + top=e.clientY; |
99 | 103 | document.body.appendChild(bigImg); |
100 | 104 | relocBigImg(left, top); |
101 | | - getImgWH(bigImg,function(){ |
102 | | - relocBigImg(left, top); |
| 105 | + getImgWH(bigImg,function(w,h){ |
| 106 | + relocBigImg(left, top, w, h); |
103 | 107 | }); |
| 108 | + bigImg.onload=function(){ |
| 109 | + relocBigImg(left, top); |
| 110 | + }; |
104 | 111 | }; |
105 | 112 | img.onmouseout=function(e){ |
106 | 113 | document.body.removeChild(bigImg); |
107 | 114 | bigImg.removeAttribute("height"); |
108 | 115 | bigImg.removeAttribute("width"); |
109 | | - bigImg.src=null; |
110 | 116 | }; |
111 | 117 | img.onmousemove=function(e){ |
112 | 118 | left=e.clientX; |
|
123 | 129 | bigImg.src=this.previousSibling.src; |
124 | 130 | bigImg.src=src; |
125 | 131 | document.body.appendChild(bigImg); |
126 | | - getImgWH(bigImg,function(){ |
127 | | - relocBigImg(left, top); |
| 132 | + getImgWH(bigImg,function(w,h){ |
| 133 | + relocBigImg(left, top, w, h); |
128 | 134 | }); |
| 135 | + bigImg.onload=function(){ |
| 136 | + relocBigImg(left, top); |
| 137 | + }; |
129 | 138 | }); |
130 | 139 | $("p").on("mouseout","div.gif-mask",function(e){ |
131 | 140 | document.body.removeChild(bigImg); |
132 | 141 | bigImg.removeAttribute("height"); |
133 | 142 | bigImg.removeAttribute("width"); |
134 | | - bigImg.src=null; |
135 | 143 | }); |
136 | 144 | $("p").on("mousemove","div.gif-mask",function(e){ |
137 | 145 | left=e.clientX; |
|
141 | 149 | } |
142 | 150 | relocBigImg(left, top); |
143 | 151 | }); |
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; |
148 | 158 | } |
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; |
151 | 161 | } |
152 | | - if(top-bigImg.height<0){ |
| 162 | + if(top-imgHeight<0){ |
153 | 163 | top=0; |
154 | 164 | }else{ |
155 | | - top-=bigImg.height; |
| 165 | + top-=imgHeight; |
156 | 166 | } |
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; |
159 | 169 | } |
160 | 170 | bigImg.style.left=left+10+"px"; |
161 | 171 | bigImg.style.top=top+"px"; |
|
0 commit comments