Skip to content

Instantly share code, notes, and snippets.

@Ramko9999
Created January 20, 2021 22:55
Show Gist options
  • Save Ramko9999/591b24dcfd6d95798cff52c2ff6189d0 to your computer and use it in GitHub Desktop.
Save Ramko9999/591b24dcfd6d95798cff52c2ff6189d0 to your computer and use it in GitHub Desktop.
const sendMessage = (toastMessage) => {
chrome.tabs.query({currentWindow:true, active:true}, (tabs) => {
const tab = tabs[0];
chrome.tabs.sendMessage(tab.id, {
toastMessage: toastMessage
});
});
}
chrome.contextMenus.onClicked.addListener(({menuItemId}) => {
if (menuItemId === "show-toast") {
chrome.storage.sync.get(["message"], ({message}) => {
sendMessage(message);
});
}
});
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "show-toast",
title: "Show Toast!",
contexts: ["all"]
});
// default message when extension is installed for the first time
chrome.storage.sync.set({message: "Hello! This is the default greeting!"});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment