Skip to content

Instantly share code, notes, and snippets.

@Ramko9999
Created January 20, 2021 22:57
Show Gist options
  • Save Ramko9999/a9c9aa38316e9fda5e2f05d5f42f0891 to your computer and use it in GitHub Desktop.
Save Ramko9999/a9c9aa38316e9fda5e2f05d5f42f0891 to your computer and use it in GitHub Desktop.
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