-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup-script.js
41 lines (35 loc) · 920 Bytes
/
popup-script.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
document.addEventListener("DOMContentLoaded", ()=>{
$('#populateNetidButton').on('click', (e)=>{
sendNetIdToContentScript()
})
//Handle enter key
$('#netId').on('keydown', (e)=> {
if (e.which == 13) {
sendNetIdToContentScript()
}
})
//Auto-populate field in the popup with synced value when popup opens
chrome.storage.sync.get(['netId'], (syncedData)=> {
if(chrome.runtime.lastError){
console.log(chrome.runtime.lastError.message)
}
if(syncedData.netId){
document.getElementById('netId').value = syncedData.netId
}
})
})
function sendNetIdToContentScript(){
chrome.tabs.query({active: true, currentWindow: true}, (tabs)=> {
let netId = document.getElementById('netId').value.trim()
chrome.storage.sync.set({
'netId': netId
})
chrome.tabs.sendMessage(
tabs[0].id, //tabs[0] just in case multiple current tabs
{
msg: 'saveNetId',
netId: netId
}
)
})
}