Skip to content

Commit

Permalink
Handle Enter key & move to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
SleekPanther committed Feb 2, 2018
1 parent 9b88e0f commit 9c62fb8
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions popup-script.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
document.addEventListener("DOMContentLoaded", ()=>{

$('#populateNetidButton').on('click', (e)=>{
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
}
)
})
sendNetIdToContentScript()
})

//Handle enter key
$('#netId').on('keydown', (e)=> {
if (e.which == 13) {
sendNetIdToContentScript()
}
})

//Auto-populate field in popup with synced value when popup opens
chrome.storage.sync.get(['netId'], (syncedData)=> {
if(chrome.runtime.lastError){
console.log(chrome.runtime.lastError.message)
Expand All @@ -26,4 +22,20 @@ document.addEventListener("DOMContentLoaded", ()=>{
}
})

})
})

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
}
)
})
}

0 comments on commit 9c62fb8

Please sign in to comment.