Last active
April 5, 2020 23:41
-
-
Save raghavraman/a4fa8b923d86b11b010ea534cc7f657b to your computer and use it in GitHub Desktop.
Dynamic Chrome extension Screen setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let userLoggedIn = false | |
function updatePopup(status) { | |
if (status === userLoggedIn) { | |
return | |
} | |
if (status) { | |
userLoggedIn = true | |
chrome.browserAction.setPopup({ popup: 'popup.html' }) | |
} else { | |
userLoggedIn = false | |
chrome.browserAction.setPopup({ popup: 'signin.html' }) | |
} | |
} | |
chrome.cookies.onChanged.addListener(changeInfo => { | |
const cookie = changeInfo.cookie | |
if (cookie.name === COOKIE_NAME && cookie.domain === `.${DOMAIN_NAME}`) { | |
updatePopup(!(changeInfo.removed)) | |
} | |
}) | |
chrome.cookies.get({ | |
url: `https://www.${DOMAIN_NNAME}`, | |
name: COOKIE_NAME | |
}, | |
cookie => { | |
if (cookie !== null) { | |
console.log(`Found ${COOKIE_NAME} on intial run`); | |
updatePopup(true); | |
console.log('set popup to popup.html'); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment