-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
46 lines (43 loc) · 1.05 KB
/
background.js
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
38
39
40
41
42
43
44
45
46
chrome.contextMenus.create(
{
type: 'normal',
title: 'Onetab',
id: 'oneTabCur',
contexts: ['all']
},
function () {
console.log(arguments)
}
)
chrome.contextMenus.onClicked.addListener(genericOnClick)
async function genericOnClick(info, tab) {
console.log(info, tab)
const menuItemId = info.menuItemId
const title = tab.title
const url = tab.url
const ico = tab.favIconUrl
const tabId = tab.id
const today = new Date()
const data = [
{
title,
url,
ico,
date: `${today.getFullYear()}/${today.getMonth() + 1}/${today.getDate()}`
}
]
if (menuItemId === 'oneTabCur') {
chrome.storage.local.get('onetab', function (res) {
let temp = res.onetab || []
temp = temp.filter(f => !data.find(d => d.url === f.url))
chrome.storage.local.set(
{ onetab: data.concat(temp) },
function () {
console.log(data)
chrome.runtime.openOptionsPage()
chrome.tabs.remove(tabId)
}
)
})
}
}