-
Notifications
You must be signed in to change notification settings - Fork 2
/
background.js
63 lines (50 loc) · 1.5 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
let counter = 0;
let ids = [];
function generateUniqueId() {
let timestamp = new Date().getTime();
timestamp = timestamp-(Math.floor(timestamp / 1000)*1000)
counter++;
return counter+timestamp ;
}
const contextMenuId = "myContextMenuOption";
chrome.runtime.onInstalled.addListener(function () {
chrome.contextMenus.create({
id: contextMenuId,
title: "Break this Article!",
contexts: ["all"],
});
});
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (!(tab.url.includes("webcache.googleusercontent"))) {
let rules = await chrome.declarativeNetRequest.getDynamicRules();
let rulesArr = []
for(let i of rules){
rulesArr.push(i.id)
}
await chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: rulesArr,
});
}
});
chrome.contextMenus.onClicked.addListener(async function (info, tab) {
if (info.menuItemId === "myContextMenuOption" && !(tab.url.includes("webcache.googleusercontent.com"))) {
let url = "http://webcache.googleusercontent.com/search?q=cache:" + tab.url;
chrome.tabs.update({ url: url });
let id = Math.floor(generateUniqueId());
console.log(id)
await chrome.declarativeNetRequest.updateDynamicRules({
addRules: [
{
id: id,
priority: 1,
action: { type: "block" },
condition: {
urlFilter:
"https://cdn-client.medium.com/lite/static/js/main*",
},
},
],
});
ids.push(id);
}
});