forked from pirate/squasher-browser-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
61 lines (56 loc) · 1.88 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
chrome.runtime.onInstalled.addListener(() => {
console.log('Domain Group Tabs extension installed.');
});
// Function to move specified tabs to a new window
function moveTabsToNewWindow(tabIds, callback) {
if (tabIds.length > 0) {
chrome.windows.create({ tabId: tabIds[0], focused: true }, function(newWindow) {
chrome.tabs.move(tabIds, { windowId: newWindow.id, index: -1 }, function() {
if (callback)
callback(newWindow.id)
});
});
}
}
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === "moveTabs") {
moveTabsToNewWindow(request.tabIds);
}
if (request.action === "closeTabs") {
for (const tabId of request.tabIds) {
chrome.tabs.remove(tabId);
}
}
if (request.action === "pocketURLs") {
moveTabsToNewWindow(request.tabIds, function(newWindowId) {
for (const tabId of request.tabIds) {
chrome.tabs.get(tabId, function(tab) {
let url = tab.url
const url_obj = new URL(tab.url)
if (url_obj.hostname == 'noogafoofpebimajpfpamcfhoaifemoa') {
// is great suspender tab
url = (new URLSearchParams(url_obj.hash)).get('uri')
}
chrome.tabs.create({
url: 'https://widgets.getpocket.com/v1/popup?url=' + encodeURIComponent(url),
windowId: newWindowId,
}, function(newTab) {
// remove pocket tab after 15
setTimeout(function() {chrome.tabs.remove(newTab.id);}, 15000)
});
});
}
// open pocket saves list after 2s
setTimeout(function() {
chrome.tabs.create({
url: 'https://getpocket.com/saves',
windowId: newWindowId,
})
}, 2000)
// close entire window after 20sec
setTimeout(function() {
chrome.windows.remove(newWindowId);
}, 20000)
});
}
});