-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.js
111 lines (79 loc) · 2.83 KB
/
logic.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
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
111
chrome.storage.sync.get("rooms", function(data) {
let rooms = data.rooms;
let room = rooms.filter(r => r.url === window.location.href)[0];
if (room) {
console.log("BBB room credentials:", room);
let codeInput = document.getElementById("room_access_code");
chrome.storage.local.get("attempts", function(data) {
if (codeInput) {
// entered code was invalid
if (data.attempts.filter(a => a.url === window.location.href)[0]) {
console.error("Invalid code. Delete room.");
chrome.storage.sync.set({"rooms": rooms.filter(r => r.url !== window.location.href)});
codeInput.form.onsubmit = function(e) {
chrome.storage.local.get("pending", function(data) {
chrome.storage.local.set({"pending": [...data.pending.filter(p => p.url !== window.location.href), {
url: window.location.href,
code: codeInput.value
}]});
});
}
} else {
console.log("Insert code");
codeInput.value = room.code;
codeInput.form.onsubmit = function(e) {
chrome.storage.local.set({"attempts": [...data.attempts, {
url: window.location.href,
code: room.code
}]});
}
codeInput.form.submit();
}
} else {
console.log("Insert name");
let nameInput = document.querySelector("[id$=join_name]");
nameInput.value = room.name;
nameInput.form.onsubmit = function(e) {
chrome.storage.sync.set({"rooms": rooms.map(r => r.url === window.location.href ? {...r, name: nameInput.value } : r)})
chrome.storage.local.set({"attempts": data.attempts.filter(a => a.url !== window.location.href)});
}
//nameInput.form.submit();
}
});
} else {
let title = document.getElementsByTagName("h1")[0];
if (title) {
let codeInput = document.getElementById("room_access_code");
if (codeInput) {
codeInput.form.onsubmit = function(e) {
chrome.storage.local.get("pending", function(data) {
chrome.storage.local.set({"pending": [...data.pending.filter(p => p.url !== window.location.href), {
url: window.location.href,
code: codeInput.value
}]});
});
}
} else {
let nameInput = document.querySelector("[id$=join_name]");
if (nameInput && nameInput.form) {
chrome.storage.local.get("pending", function(data) {
let pending = data.pending.filter(p => p.url === window.location.href)[0];
if (pending) {
nameInput.form.onsubmit = function(e) {
let newRoom = {
title: title.innerText,
url: window.location.href,
code: pending ? pending.code : "",
name: nameInput.value,
microphone: false
};
chrome.storage.sync.set({"rooms": [newRoom, ...rooms]});
chrome.storage.local.set({"pending": data.pending.filter(p => p.url !== window.location.href)});
}
}
});
}
}
}
}
});