forked from thosmos/filelink-owncloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanagement.js
68 lines (62 loc) · 2.08 KB
/
management.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
let form = document.querySelector("form");
let webdavUrl = form.querySelector(`input[name="webdavUrl"]`);
let username = form.querySelector(`input[name="username"]`);
let token = form.querySelector(`input[name="token"]`);
let path = form.querySelector(`input[name="path"]`);
let button = form.querySelector("button");
let accountId = new URL(location.href).searchParams.get("accountId");
(() => {
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 ("webdavUrl" in accountInfo[accountId]) {
webdavUrl.value = accountInfo[accountId].webdavUrl;
}
if ("username" in accountInfo[accountId]) {
username.value = accountInfo[accountId].username;
}
if ("token" in accountInfo[accountId]) {
token.value = accountInfo[accountId].token;
}
if ("path" in accountInfo[accountId]) {
path.value = accountInfo[accountId].path;
}
}
});
button.onclick = async () => {
if (!form.checkValidity()) {
console.log("form is invalid");
return;
}
webdavUrl.disabled = username.disabled = token.disabled = path.disabled = button.disabled = true;
let webdavUrl_value = webdavUrl.value;
if (!webdavUrl_value.endsWith("/")) {
webdavUrl_value += "/";
webdavUrl.value = webdavUrl_value;
}
let path_value = path.value;
if (!path_value.endsWith("/")) {
path_value += "/";
path.value = path_value;
}
if (!path_value.startsWith("/")) {
path_value = "/" + path_value;
path.value = path_value;
}
let start = Date.now();
await browser.storage.local.set({
[accountId]: {
webdavUrl: webdavUrl_value,
username: username.value,
token: token.value,
path: path_value
},
});
await browser.cloudFile.updateAccount(accountId, { configured: true });
setTimeout(() => {
webdavUrl.disabled = username.disabled = token.disabled = path.disabled = button.disabled = false;
}, Math.max(0, start + 500 - Date.now()));
};