-
Notifications
You must be signed in to change notification settings - Fork 6
/
clk.js
62 lines (48 loc) · 1.78 KB
/
clk.js
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
/*
@clk.js
@author: Dingbao.ai[aka. ehaagwlke]
@date: 2011-01-02
@version:0.0.0.6
*/
var imgInfoObj={},alt='',title='',altTitleStr='',dispWidth=0,dispHeight=0;
var ciid=chrome.contextMenus.create({
"type":"normal",
"title":chrome.i18n.getMessage("contextMenuStr"),
"contexts":["image"],
"onclick":evt
});
chrome.tabs.onSelectionChanged.addListener(function(tid,info){
alt='';
title='';
altTitleStr='';
dispWidth=0;
dispHeight=0;
});
chrome.extension.onRequest.addListener(function(request){
alt=request.alt?request.alt:'';
title=request.title?request.title:'';
if(alt&&title) altTitleStr=alt+' / '+title;
if(alt&& !title) altTitleStr=alt+ ' / --';
if(!alt && title) altTitleStr='-- / '+title;
if(!alt && !title) altTitleStr='-- / --';
dispWidth=request.dispWidth?request.dispWidth:0;
dispHeight=request.dispHeight?request.dispHeight:0;
});
function evt(info,tab){
//the location of the image
var imgSrc=info.srcUrl,
//image src link type, base64 or ordinary link
linkType,
//image url length, the window width will be the url length times 7
linkLength,
//url of the tab which the image embedded
tabUrl=tab.url,
//the width of the popup window
popWinWidth,popWinHeight;
linkType = (imgSrc.indexOf('data:image/') == 0 && imgSrc.indexOf('base64') > -1) ? "base64" : "normal";
linkLength = linkType == "normal" ? imgSrc.length : 75;
popWinWidth = linkLength < 75 ? linkLength*8+100:800;
popWinHeight = 220;
chrome.windows.create({"type":"panel","focused": true,"url":"vii.html","width":popWinWidth,"height":popWinHeight});
imgInfoObj={"imgSrc":imgSrc,"linkType":linkType,"tabUrl":tabUrl,"popWinWidth":popWinWidth,"popWinHeight":popWinHeight,"linkLength":linkLength,"altTitleStr":altTitleStr,"dispWidth":dispWidth,"dispHeight":dispHeight};
}