-
Notifications
You must be signed in to change notification settings - Fork 6
/
vii.html
199 lines (170 loc) · 7.43 KB
/
vii.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>View Image Info [loading...]</title>
<style type="text/css">
body,table,tr,td,em,img,a{padding:0;margin:0;font-size:14px;font-family:arial,sans-serif;}
table{width:100%;}
body{max-height:600px;color:#000}
td:first-child{text-align:right;min-width:100px;color:#666666;padding-right: 5px;}
tr:nth-child(odd){background:#E7E7E7;}
tr:nth-child(even){background:#FEFEFE;}
td em{font-weight:bold;font-style:normal;}
td{line-height:150%;text-indent:8px;height:150%;}
td img{padding:5px 2px;max-width: 600px;}
tr:last-child td:first-child{vertical-align:top;}
td a{display: block;word-break:keep-all;white-space:nowrap;}
tr td.error{color:#c7c7c7;}
tr td span.gray{color:#888888}
</style>
</head>
<body>
<table></table>
</body>
</html>
<script type="text/javascript">
//functions for getting i18n messages and elements
function g(s){return chrome.i18n.getMessage(s);}
function gtn(t){return document.getElementsByTagName(t);}
//formatting the number for displaying
//here I know all numbers will be integers
//if used elsewhere, some more conditional
//tests should be made
function fnum(ns){
if(!ns) return;
var ns=ns.toString(),op,j=0;
if(ns.length>3){
var nsl=ns.length,ca=[];
for(var i=nsl-1;i>-1;i--){
++j;
var cae=ns.substr(i,1);
if(j==3 && i !=0) {cae=','+cae; j=0;}
ca[i]=cae;
}
op = ca.join('');
}else{
op = ns;
}
return op;
}
//when the esc key released, close the info window
//there are two ways to close this window, one is
//traditional window.close(), the other is used below
//Using keydown event makes people feel the interface
//responsing faster, keyup does the opposite.
document.body.onkeydown=function(e){
if(e.keyCode && e.keyCode == 27){
chrome.windows.getCurrent(function(w){
chrome.windows.remove(w.id);
});
}
}
//display initial contents of the window
var bg=chrome.extension.getBackgroundPage(),info=bg.imgInfoObj;
var c = '<tr><td>'+g('loc')+': </td><td><a href="'+info['imgSrc']+'" target="_blank">'+info['imgSrc']+'</a></td></tr>';
c+= '<tr><td>'+g('dims')+': </td><td><img src="loading-s.gif" /></td></tr>';
c+= '<tr><td>'+g('ftype')+': </td><td><img src="loading-s.gif" /></td></tr>';
c+= '<tr><td>'+g('fsize')+': </td><td><img src="loading-s.gif" /></td></tr>';
c+= '<tr><td>'+g('alt')+' / '+g('title')+': </td><td><img src="loading-s.gif" /></td></tr>';
c+= '<tr><td>'+g('prev')+': </td><td><img src="loading-s.gif" /></td></tr>';
gtn('table')[0].innerHTML = c;
//calculating the size of the window
//using XMLHttpRequest object to get the file size and file type
//of the image file
var tds=gtn('td'),xhr=new XMLHttpRequest(),imgType,imgFileSize,oImgFileSize,dispImgFileSize;
var altTitleStr=info['altTitleStr'];
tds[9].innerHTML = altTitleStr;
var nImg = new Image();
nImg.src=info['imgSrc'];
nImg.onload=function(){
var nImgWidth=nImg.width,nImgHeight=nImg.height,nImgDims,newImgWidth,newImgHeight;
var dispWidth=info['dispWidth'],dispHeight=info['dispHeight'],sw,sh,sstr='';
sw=dispWidth!=nImgWidth?dispWidth:0;
sh=dispHeight!=nImgHeight?dispHeight:0;
if(sw&&sh)sstr='<span class="gray">('+g('smsg')+' '+sw+' x '+sh+' px)</span>';
//generating the image dimensions string
nImgDims = nImgWidth&&nImgHeight ? nImgDims=nImgWidth+' x '+nImgHeight+' px '+sstr: g('eid');
tds[3].innerHTML = nImgDims;
//resize the image if height or width or both
//are larger than 600, and updating the size
//of the info window according to these two
//numbers, and show the scroll bar if needed
newImgWidth = nImgWidth >= 600 ? 600 : nImgWidth;
newImgHeight = nImgWidth >= 600 ? Math.ceil(600*nImgHeight/nImgWidth) : nImgHeight;
var imgURLWidth=info['imgSrc'].length*8;
imgURLWidth = imgURLWidth > 680 ? 680 : imgURLWidth;
var popWinNewHeight=info['popWinHeight']+newImgHeight-16;
popWinNewHeight = popWinNewHeight > 600 ? 600 : popWinNewHeight;
if(popWinNewHeight==600)document.body.style.overFlowY = "scroll";
if(newImgWidth>imgURLWidth&&newImgWidth>popWinNewHeight-120){
document.body.style.overFlowX="scroll";
chrome.windows.getCurrent(function(w){
chrome.windows.update(w.id,{width:newImgWidth+125});
});
}
chrome.windows.getCurrent(function(w){
chrome.windows.update(w.id,{height:popWinNewHeight});
});
}
//if the image can not be loaded
//error message should be in different color
nImg.onerror=function(){
document.title="View Image Info [error occurred]";
tds[3].innerHTML=g('eid');
tds[5].innerHTML=g('eift');
tds[7].innerHTML=g('eifz');
tds[11].innerHTML=g('ilem');
tds[3].style.color=tds[5].style.color=tds[7].style.color=tds[9].style.color=tds[11].style.color='#999999';
}
//show the image before the xmlhttprequest request will be sent
tds[11].firstChild.src=nImg.src;
//'cause image could be embedded in a web page
//using base64 data, so we handle it seperately
//what about svg?
if(info['linkType']!='base64'){
xhr.open("GET",nImg.src,true);
xhr.onreadystatechange=function(){
if(xhr.status==200&&xhr.readyState==4){
imgType=xhr.getResponseHeader("Content-Type").split("/")[1],
oImgFileSize=xhr.getResponseHeader("Content-Length");
//format the number for better readability
dispImgFileSize = fnum(oImgFileSize);
if(oImgFileSize<=1024) imgFileSize = dispImgFileSize+' bytes';
if(oImgFileSize>1024 && oImgFileSize<=1024000) imgFileSize = (oImgFileSize/1024).toFixed(2)+' KB <span class="gray">('+dispImgFileSize+' bytes)</span>';
if(oImgFileSize>1024000)imgFileSize=(oImgFileSize/1024/1024).toFixed(2)+' MB <span class="gray">('+dispImgFileSize+' bytes)</span>';
if(parseInt(imgFileSize)>0){
tds[7].innerHTML = imgFileSize;
}else{
tds[7].innerHTML=g('eifz');
tds[7].style.color="#999999";
}
imgType = (imgType&&imgType.toLowerCase()!="html") ? '<em>'+imgType.toUpperCase()+'</em> image' : g('eift');
tds[5].innerHTML=imgType;
if(imgType==g('eift')) tds[5].style.color="#999999";
document.title="View Image Info";
//will this conditional test cause any problem?
}else if(xhr.status>=300){
document.title="View Image Info [error occurred]";
tds[5].innerHTML=g('eift');
tds[7].innerHTML=g('eifz');
tds[5].style.color=tds[7].style.color="#999999";
}
}
xhr.send(null);
//to do:there should be a function to
//stop the xmlhttprequest request if
//it takes too long to get response.
//the time should be, say, 30sec.
//if the image source is base64 data
//file size will be unavailable
}else{
document.title="View Image Info [Base64 data]";
imgType='<em>'+info['imgSrc'].substring(11,info['imgSrc'].indexOf(';')).toUpperCase()+'</em> image (base64 data)';
imgFileSize=g('eifz');
tds[5].innerHTML=imgType;
tds[7].innerHTML=imgFileSize;
tds[7].style.color="#999999";
}
</script>
<script type="text/javascript" src="analytics.js"></script>