forked from kreativgebiet/taskana
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbrowser.cjs
68 lines (56 loc) · 2.24 KB
/
browser.cjs
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
const { ipcRenderer } = require('electron');
const keyStore = import('./src/keystore.js');
ipcRenderer.on('new-task', () => {
document.querySelector('.Omnibutton').click();
document.querySelector('.Omnibutton-task').click();
});
ipcRenderer.on('show-preferences', () => {
document.querySelector('.TopbarSettingsMenuButton')?.click();
document.querySelector('.TopbarSettingsMenu-settings')?.click();
});
document.addEventListener('readystatechange', async () => {
const DomHooks = {
loginform: '.LoginEmailPasswordForm',
loginusername: 'input[name=e]',
loginpassword: 'input[name=p]',
loginbutton: '[role=button]',
};
if (document.location.pathname.endsWith('/login')) {
const loginform = document.querySelector(DomHooks.loginform);
const loginusername = loginform.querySelector(DomHooks.loginusername);
const loginpassword = loginform.querySelector(DomHooks.loginpassword);
// try using saved login
const loginkeys = await keyStore.getKey();
// Trigger the attached `change` event to get the values into the Virtual DOM (as Asana runs React/Nuxt.js)
const event = new Event('HTMLEvents');
event.initEvent('change', true, false);
if (loginkeys?.username) {
loginusername.value = loginkeys.username;
loginusername.dispatchEvent(event);
}
if (loginkeys?.password) {
loginpassword.value = loginkeys.password;
loginpassword.dispatchEvent(event);
}
const loginsubmitted = async () => {
const username = loginusername.value;
const password = loginpassword.value;
if (username && password) {
await keyStore.deleteKeys(); // delete any exiting logins
await keyStore.addKey(username, password); // store the users details for auto-login next time
}
};
// add a listener to the form to capture login details and store them
// would be nice to add to just the <FORM> submit event, but React/Nuxt (used by Asana) captures the events lower in the DOM
// loginform.addEventListener('submit', loginsubmitted);
loginform
.querySelector(DomHooks.loginbutton)
.addEventListener('click', loginsubmitted);
loginusername.addEventListener('keyup', (e) => {
if (e.code === 'Enter') loginsubmitted();
});
loginpassword.addEventListener('keyup', (e) => {
if (e.code === 'Enter') loginsubmitted();
});
}
});