Created
January 20, 2021 22:55
-
-
Save Ramko9999/591b24dcfd6d95798cff52c2ff6189d0 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 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