-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.html
108 lines (98 loc) · 2.87 KB
/
background.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
<html>
<head>
<script>
function clone(obj){
var newObj = (obj instanceof Array) ? [] : {};
for (var i in obj) {
if (obj[i] && typeof obj[i] == "object")
newObj[i] = clone(obj[i]);
else
newObj[i] = obj[i];
}
return newObj;
}
var urlPatterns = [
'http://*.static.flickr.com/*/*_*',
'http://*.ak.fbcdn.net/*/*/*_*_*',
'http://upload.wikimedia.org/wikipedia/commons/*/*/*',
'http://*.ffffound.com/static-data/assets/*/*_*',
'http://ssssave.com/store/img/*/*_*',
'http://svpply.s3.amazonaws.com/*/*.*',
'http://i.imgur.com/*.*',
'http://imgur.com/*.*'
];
var properties = {
"title": "View Source",
"contexts": ['image'],
"onclick": function(info, tab) {
patterns = [
{
url: "http://www.flickr.com/photo.gne?id=",
pattern: "^http://.*?.?static.flickr.com/.*?/(.*?)_.*?",
url_pattern: "^http://www.flickr.com\/photos\/.*?\/[0-9]+(?:\/.*?)?"
},
{
url: "http://www.facebook.com/photo.php?fbid=",
pattern: "^http://.*?.ak.fbcdn.net/.*?/(?:.*?/)?.*?_(.*?)_.*?",
url_pattern: "^http://www.facebook.com/photo.php\\?fbid=.+"
},
{
url: "http://en.wikipedia.org/wiki/File:",
pattern: "^http://upload.wikimedia.org/wikipedia/commons/thumb/.*?/.*?/(.*?)/.*?"
},
{
url: "http://en.wikipedia.org/wiki/File:",
pattern: "^http://upload.wikimedia.org/wikipedia/commons/.*?/.*?/(.*)"
},
{
url: "http://ffffound.com/image/",
pattern: "^http://.*?.ffffound.com/static-data/assets/.*?/(.*?)_.*?"
},
{
url: "http://ssssave.com/image/",
pattern: "^http://ssssave.com/store/img/.*?/(.*?)_.*?"
},
{
url: "http://svpply.com/item/",
pattern: "^http://assets.svpply.com.s3.amazonaws.com/.*?/(\\d+)..*?"
},
{
url: "http://imgur.com/gallery/",
pattern: "^http://i?.?imgur.com/([a-zA-Z0-9]*).[a-z]+"
}
];
for(i in patterns) {
pattern = patterns[i].url_pattern ? patterns[i].url_pattern : "^" + patterns[i].url + ".+";console.log(pattern);console.log(tab.url);console.log(new RegExp(pattern).exec(tab.url));
if(!new RegExp(pattern).exec(tab.url)) {
match = new RegExp(patterns[i].pattern).exec(info.srcUrl);
if(match && match[1]) {
chrome.tabs.create({"url":patterns[i].url+match[1]});
return;
}
}
}
chrome.tabs.create({"url":"http://www.google.com/searchbyimage?image_url="+encodeURIComponent(info.srcUrl)});
}
};
var context = null;
function createContext() {
var p = clone(properties);
if(localStorage["Google"] == "false") {
p.targetUrlPatterns = urlPatterns;
}
context = chrome.contextMenus.create(p);
}
createContext();
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
switch(request.action){
case "setGoogle":
localStorage["Google"] = request.value;
chrome.contextMenus.remove(context);
createContext();
break;
}
});
</script>
</head>
</html>