-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (27 loc) · 1.04 KB
/
background.js
File metadata and controls
32 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Define a variable to track whether the context menu item has been created
let contextMenuItemCreated = false;
chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.set({searchTiming: 'Now'}, function() {
console.log('Search timing is set to Now.');
});
// Check if the context menu item has already been created
if (!contextMenuItemCreated) {
// If it hasn't been created, create it
chrome.contextMenus.create({
title: 'Search Letterboxd',
contexts: ['selection'],
id: 'searchLetterboxdContextMenu'
});
contextMenuItemCreated = true;
}
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId === 'searchLetterboxdContextMenu') {
chrome.tabs.create({url: 'https://letterboxd.com/search/films/' + encodeURIComponent(info.selectionText)});
}
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === 'getSelectedText') {
sendResponse({selectedText: window.getSelection().toString()});
}
});