-
Notifications
You must be signed in to change notification settings - Fork 2
/
background.html
110 lines (100 loc) · 3.05 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
109
110
<html>
<head>
<script type=""text/css">
var next_click_to_edit = false;
function hasConnection() {
var plugin = document.getElementById("proxy_plugin");
return plugin && plugin.connectionName != "__No connection__";
}
function updateUI() {
var plugin = document.getElementById("proxy_plugin");
plugin = document.getElementById("proxy_plugin");
var icon_path = "proxy_off.png";
var name = plugin.connectionName;
var title;
var popup_html = "";
if (!hasConnection()) {
title = chrome.i18n.getMessage("noConnection");
icon_path = "no_connection.png";
} else {
var config = plugin.getProxyConfig();
var proxy_state = chrome.i18n.getMessage("noProxy");
if (config.useProxy) {
icon_path = "proxy_on.png";
proxy_state = chrome.i18n.getMessage("proxyIs") + config.proxyServer;
if (next_click_to_edit) {
proxy_state += chrome.i18n.getMessage("inPlaceEditPrompt");
icon_path = "proxy_can_edit.png";
popup_html = "popup.html";
}
} else {
if (!config.proxyServer) {
// Let user directly open the popup when we don't have proxies defined.
popup_html = "popup.html";
}
}
title = plugin.connectionName + " " + proxy_state;
}
chrome.browserAction.setIcon({path: icon_path});
chrome.browserAction.setTitle({title: title});
chrome.browserAction.setPopup({popup: popup_html});
}
function disablePopup () {
if (next_click_to_edit) {
next_click_to_edit = false;
updateUI();
}
}
chrome.browserAction.onClicked.addListener(function(tab) {
var use_proxy;
if (hasConnection()) {
var plugin = document.getElementById("proxy_plugin");
var config = plugin.getProxyConfig();
use_proxy = !config.useProxy;
if (use_proxy && !config.proxyServer) {
use_proxy = false;
} else {
plugin.setProxyConfig(use_proxy);
}
}
next_click_to_edit = use_proxy;
updateUI();
});
chrome.tabs.onCreated.addListener(function(tab) {
updateUI();
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
updateUI();
});
function loadProxyList() {
var str = localStorage["proxyList"];
if (!str || str == "") {
return [];
}
var proxyList = JSON.parse(str);
return proxyList;
}
function storeProxyList(proxyList) {
var str = JSON.stringify(proxyList);
localStorage["proxyList"] = str;
}
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.message == "refresh") {
updateUI();
} else if (request.message == 'loadproxylist') {
var proxyList = loadProxyList();
sendResponse({list: proxyList});
} else if (request.message == 'storeproxylist') {
storeProxyList(request.data);
}
next_click_to_edit = true;
// Automatically close editing after 5 seconds.
setTimeout("disablePopup();", 5000);
});
</script>
</head>
<body onload="updateUI();">
<embed id="proxy_plugin" type="application/x-switch-proxy" hidden="true">
</body>
</html>