Created
January 20, 2021 22:57
-
-
Save Ramko9999/a9c9aa38316e9fda5e2f05d5f42f0891 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const showToast = (message) => { | |
//append html element to webpage | |
let toastContainer = document.createElement("div"); | |
toastContainer.innerText = message; | |
toastContainer.className = "toast"; | |
document.body.appendChild(toastContainer); | |
//remove element after 2 seconds | |
setTimeout(()=>{ | |
document.body.removeChild(toastContainer); | |
}, 2000); | |
}; | |
chrome.runtime.onMessage.addListener((request, _, sendResponse) => { | |
if("toastMessage" in request){ | |
showToast(request.toastMessage); | |
sendResponse({status: "OK"}); | |
} | |
else{ | |
sendResponse({status: "FAIL", | |
message: "toastMessage not provided"}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment