-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
126 lines (107 loc) · 3.85 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// First event
// If you define default_popup in manifest, you cannot use chrome.browserAction.onClicked.addListener method,
// it will throw error
// chrome.browserAction.onClicked.addListener(buttonClicked);
// function buttonClicked() {
// console.log("button is clicked in buttonclicked handler");
// }
// You can send the message from all the tab or unique tab using
// let msg: {
// txt: "hello"
// }
// chrome.tabs.sendMessage(tab.id, msg)
chrome.runtime.onInstalled.addListener(function () {
// chrome.storage.sync.set({ color: "#3aa757" }, function () {
// console.log("The color is green.");
// });
// if (chrome.declarativeContent.onPageChanged) {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function () {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
// new chrome.declarativeContent.PageStateMatcher({
// pageUrl: { pathContains: "", },
// }),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlPrefix: "https://" },
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlPrefix: "http://" },
}),
],
actions: [new chrome.declarativeContent.ShowPageAction()],
},
]);
});
// }
chrome.runtime.onMessage.addListener(function (message, sender, callback) {
// console.log("sender", sender);
// console.log("message", message);
if (message.type === "trigger_redirection_tosuspended_page") {
// I need to create the redirection link for the
const { tab } = sender;
// FOr not i have to give some amount of timeout to show notification
setTimeout(() => {
chrome.tabs.update(tab.id, {
url: chrome.runtime.getURL(
`pages/suspendedpage.html?url=${tab.url}&title=${tab.title}`
),
});
}, 4000);
var opt = {
iconUrl: "images/get_started32.png",
type: "list",
title: "Primary Title",
message: "Primary message to display",
priority: 1,
items: [
{ title: "Item1", message: "This is item 1." },
{ title: "Item2", message: "This is item 2." },
{ title: "Item3", message: "This is item 3." },
],
};
// chrome.notifications.create(`${Math.random()}`, opt, function callback() {
// console.log("created!");
// console.log("Last error:", chrome.runtime.lastError);
// });
}
if (message == "reload") {
chrome.tabs.executeScript({
code: 'document.body.style.backgroundColor="orange"',
});
}
});
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
// console.log("tabId, changeInfo,tab", tabId, changeInfo, tab);
});
// chrome.runtime.onInstalled.addListener(function () {
// chrome.contextMenus.create({
// id: "sampleContextMenu",
// title: "Sample Context Menu",
// contexts: ["selection"],
// });
// });
// chrome.contextMenus.create({
// id: "sampleContextMenu",
// title: "Sample Context Menu",
// contexts: ["selection"], // only show context menu on selection
// });
// // You can have more options to add the context menus. check the documentation for
// // chrome.contextMenus
// chrome.contextMenus.onClicked.addListener(() => {
// console.log("context menu clicked");
// });
// This will run when a bookmark is created. need permission
// chrome.bookmarks.onCreated.addListener(function () {
// // do something
// });
});
// chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
// console.log(
// sender.tab
// ? "from a content script:" + sender.tab.url
// : "from the extension"
// );
// if (request.greeting == "hello") sendResponse({ farewell: "goodbye" });
// });
// Do not register listeners asynchronously