forked from estum/Google-Image-Search-safariextension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.html
64 lines (54 loc) · 1.92 KB
/
global.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
<!DOCTYPE HTML>
<html>
<head>
<title>Search Image in Google</title>
<script src="port.js"></script>
<script type="text/javascript">
var imageGoogleSearchURL = 'http://www.google.com/searchbyimage?sbisrc=cr_1_0_0&image_url=';
var allowSearchByBackgroundImage = safari.extension.settings.search_by_background_image;
function translate(messageID, args) {
return chrome.i18n.getMessage(messageID, args);
}
function getLocalizedString (key)
{
try {
var ret = localizedStrings[key];
if (ret === undefined)
ret = key;
return ret;
} catch (ex) {}
return key;
}
function settingsChanged(event) {
if (event.key == "search_by_background_image") {
allowSearchByBackgroundImage = event.newValue;
}
}
safari.extension.settings.addEventListener("change", settingsChanged, false);
function respondSettings(theMessageEvent) {
if(theMessageEvent.name === "requestSettings") {
theMessageEvent.target.page.dispatchMessage("settings", allowSearchByBackgroundImage);
}
}
safari.application.addEventListener("message", respondSettings, false);
function commandSearchImage(event) {
if (event.command === 'search_image' &&
event.userInfo.ifImage &&
event.userInfo.imageSrc.length > 0) {
var url = imageGoogleSearchURL + encodeURIComponent(event.userInfo.imageSrc);
var newTab = safari.application.activeBrowserWindow.openTab().url = url;
}
}
function validateSearchImage(event) {
event.target.title = translate("search_google_image");
if (!event.userInfo.ifImage) {
event.target.disabled = true;
}
}
safari.application.addEventListener("command", commandSearchImage, false);
safari.application.addEventListener("validate", validateSearchImage, false);
</script>
</head>
<body>
</body>
</html>