-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanagement.js
More file actions
107 lines (92 loc) · 3.1 KB
/
management.js
File metadata and controls
107 lines (92 loc) · 3.1 KB
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
let info = document.querySelector("form");
let private_url = info.querySelector(`input[name="private_url"]`);
let public_url = info.querySelector(`input[name="public_url"]`);
let id = info.querySelector(`input[name="id"]`);
let pass = info.querySelector(`input[name="pass"]`);
let button = info.querySelector("button");
let accountId = new URL(location.href).searchParams.get("accountId");
let confirmText = info.querySelector(`p[name="confirm"]`);
let wrongPass = info.querySelector(`p[name="wrong"]`);
(() => {
for (let element of document.querySelectorAll("[data-message]")) {
element.textContent = browser.i18n.getMessage(element.dataset.message);
}
})();
browser.storage.local.get([accountId]).then(accountInfo => {
if (accountId in accountInfo) {
if ("private_url" in accountInfo[accountId]) {
private_url.value = accountInfo[accountId].private_url;
}
if ("public_url" in accountInfo[accountId]) {
public_url.value = accountInfo[accountId].public_url;
}
if ("id" in accountInfo[accountId]) {
id.value = accountInfo[accountId].id;
}
if ("pass" in accountInfo[accountId]) {
pass.value = accountInfo[accountId].pass;
}
}
});
button.onclick = async () => {
if(id.value==""){
id.style.border = "1px solid #ff0000";
return;
}
else{
id.style.border = "1px solid gray";
};
if (pass.value==""){
pass.style.border = "1px solid #ff0000";
return;
}
else{
pass.style.border = "1px solid gray";
};
if (!info.checkValidity()) {
return;
};
private_url.disabled = public_url.disabled = button.disabled = id.disabled = pass.disabled = true;
let private_url_value = private_url.value;
if (!private_url_value.endsWith("/")) {
private_url_value += "/";
private_url.value = private_url_value;
};
let headers = {
"Content-Type": "application/octet-stream",
};
headers.Authorization = "Basic " + window.btoa(id.value + ":" + pass.value);
let test_credentials = {
method: "GET",
headers,
};
validation_url = private_url_value + "api/folders?action=getAll";
response = await fetch(validation_url, test_credentials);
if (response.status >= 400){
pass.style.border = "2px solid #ff0000";
pass.value = ""
window.setTimeout(()=>pass.style.border = "2px solid gray", 2000);
wrongPass.style.display = "block";
confirmText.style.display = "none";
} else {
pass.style.border = "2px solid #90ee90";
window.setTimeout(()=>pass.style.border = "2px solid gray", 2000);
confirmText.style.display = "block";
wrongPass.style.display = "none";
}
let public_url_value = public_url.value || private_url_value;
public_url.value = public_url_value;
let start = Date.now();
await browser.storage.local.set({
[accountId]: {
private_url: private_url_value,
public_url: public_url_value,
id: id.value,
pass: pass.value
},
});
await browser.cloudFile.updateAccount(accountId, { configured: true });
setTimeout(() => {
private_url.disabled = public_url.disabled = button.disabled = id.disabled = pass.disabled = false;
}, Math.max(0, start + 500 - Date.now()));
};