-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathforeground.js
38 lines (31 loc) · 1.07 KB
/
foreground.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
const ce_main_container = document.createElement('DIV');
const ce_name = document.createElement('DIV');
const ce_input = document.createElement('INPUT');
const ce_button = document.createElement('DIV');
ce_main_container.classList.add('ce_main');
ce_name.id = 'ce_name';
ce_input.id = 'ce_input';
ce_button.id = 'ce_button';
ce_name.innerHTML = `Hello NAME`;
ce_button.innerHTML = `Change name.`;
ce_main_container.appendChild(ce_name);
ce_main_container.appendChild(ce_input);
ce_main_container.appendChild(ce_button);
document.querySelector('body').appendChild(ce_main_container);
chrome.runtime.sendMessage({
message: "get_name"
}, response => {
if (response.message === 'success') {
ce_name.innerHTML = `Hello ${response.payload}`;
}
});
ce_button.addEventListener('click', () => {
chrome.runtime.sendMessage({
message: "change_name",
payload: ce_input.value
}, response => {
if (response.message === 'success') {
ce_name.innerHTML = `Hello ${ce_input.value}`;
}
});
});