-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
36 lines (34 loc) · 1.26 KB
/
background.js
File metadata and controls
36 lines (34 loc) · 1.26 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
33
34
35
36
// Listen for extension icon clicks
chrome.action.onClicked.addListener((tab) => {
chrome.tabs.sendMessage(tab.id, { action: "convertToMarkdown" }, (response) => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
showNotification('Error', 'Failed to access the page. Please refresh and try again.');
}
});
});
// Listen for keyboard shortcuts
chrome.commands.onCommand.addListener(async (command) => {
if (command === "convert-to-markdown") {
const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
if (!tab) {
showNotification('Error', 'No active tab found.');
return;
}
chrome.tabs.sendMessage(tab.id, { action: "convertToMarkdown" }, (response) => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
showNotification('Error', 'Failed to access the page. Please refresh and try again.');
}
});
}
});
// Function to show Chrome notifications
function showNotification(title, message) {
chrome.notifications.create({
type: 'basic',
iconUrl: 'icons/icon48.png',
title: title,
message: message
});
}