-
Notifications
You must be signed in to change notification settings - Fork 4
/
modal.js
54 lines (45 loc) · 1.39 KB
/
modal.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
var user = document.getElementById("username");
var pw = document.getElementById("pw");
var all_ports = document.getElementById("all-ports");
var submit = document.getElementById("submit");
var cancel = document.getElementById("cancel");
function findGetParameter(parameterName) {
var result = null,
tmp = [];
location.search
.substr(1)
.split("&")
.forEach(function (item) {
tmp = item.split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
});
return result;
}
function isDefaultPort(host) {
return host.split(":").length == 1;
}
var host = findGetParameter("host");
var url = findGetParameter("url");
var is_error = findGetParameter("is_error") == 'true';
submit.onclick = function(e) {
e.preventDefault();
if (all_ports.checked) {
host = host.split(':')[0] + ':' + '*';
}
browser.storage.local.set({[host]: {username: user.value, password: pw.value}});
location.href = url;
}
cancel.onclick = function(e) {
e.preventDefault();
if (all_ports.checked) {
host = host.split(':')[0] + ':' + '*';
}
browser.storage.local.set({[host]: "ignored"});
location.href = url;
}
if (is_error) {
document.getElementById("error-banner").removeAttribute("hidden");
}
if (!isDefaultPort(host)) {
document.getElementById("port-container").style.display = "block";
}