mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-27 13:29:34 +07:00
* Update dictionary sample to use sidePanel.open() Updates the dictionary side panel example to use the sidePanel.open() API. This means we are also able to demonstrate a way of safely passing data to the side panel without hitting any race conditions. * Address feedback
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
// Copyright 2023 Google LLC
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
function setupContextMenu() {
|
|
chrome.contextMenus.create({
|
|
id: 'define-word',
|
|
title: 'Define',
|
|
contexts: ['selection']
|
|
});
|
|
}
|
|
|
|
chrome.runtime.onInstalled.addListener(() => {
|
|
setupContextMenu();
|
|
});
|
|
|
|
chrome.contextMenus.onClicked.addListener((data, tab) => {
|
|
// Store the last word in chrome.storage.session.
|
|
chrome.storage.session.set({ lastWord: data.selectionText });
|
|
|
|
// Make sure the side panel is open.
|
|
chrome.sidePanel.open({ tabId: tab.id });
|
|
});
|