-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
58 lines (54 loc) · 2.09 KB
/
popup.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
function connect() {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
const port = chrome.tabs.connect(tabs[0].id);
port.postMessage({function: 'html'});
port.onMessage.addListener((response) => {
let sessionStatus = response.status;
if (sessionStatus) {
document.getElementById('shoeSwitchKey').checked = sessionStatus;
dropdownVisibility(sessionStatus);
} else {
document.getElementById('shoeSwitchKey').checked = sessionStatus;
dropdownVisibility(sessionStatus);
}
})
})
}
window.addEventListener('load', (event) => {
chrome.tabs.query({active: true, currentWindow: true}, function (activeTabs) {
chrome.tabs.executeScript(activeTabs[0].id, {file: 'content.bundle.js'}, () => {
connect();
});
});
});
document.getElementById('shoeSwitchKey').addEventListener('change', function () {
let getCheckBox = this.checked;
dropdownVisibility(getCheckBox);
chrome.tabs.query({active: true, currentWindow: true}, function (activeTabs) {
chrome.tabs.executeScript(activeTabs[0].id, {
code: `var status = ${getCheckBox}`
}, function () {
chrome.tabs.executeScript(activeTabs[0].id, {file: 'sessionStorage.js'});
});
});
});
document.getElementById('cusDropdown').addEventListener('click', ev => {
if (ev.target.className === 'selImg') {
var clickedImgId = ev.target.id;
chrome.tabs.query({active: true, currentWindow: true}, function (activeTabs) {
chrome.tabs.executeScript(activeTabs[0].id, {
code: `var imgId = "${clickedImgId}"`
}, function () {
chrome.tabs.executeScript(activeTabs[0].id, {file: 'insertImg.js'});
});
});
}
});
function dropdownVisibility(checked) {
const getDrobdown = document.getElementById('cusDropdown');
if (checked === true) {
getDrobdown.style.display = 'block';
} else {
getDrobdown.style.display = 'none';
}
}