-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
37 lines (34 loc) · 1014 Bytes
/
background.js
File metadata and controls
37 lines (34 loc) · 1014 Bytes
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
37
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "saveToMyMind",
title: "Save to My Mind",
contexts: ["selection", "link"]
});
});
chrome.contextMenus.onClicked.addListener((info) => {
if (info.menuItemId === "saveToMyMind") {
const content = info.selectionText || info.linkUrl;
const isLink = /^(http|https):\/\/[^ "]+$/.test(content);
const date = new Date().toLocaleString('en-GB');
chrome.storage.sync.get(['myData'], (res) => {
const list = res.myData || [];
list.unshift({
category: isLink ? "Link" : "Note",
content: content,
date: date,
id: Date.now(),
pinned: false
});
chrome.storage.sync.set({ myData: list });
});
}
});
chrome.alarms.onAlarm.addListener((alarm) => {
chrome.notifications.create({
type: 'basic',
iconUrl: 'icon.png',
title: 'My Mind Reminder',
message: alarm.name,
priority: 2
});
});