-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
32 lines (27 loc) · 983 Bytes
/
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
chrome.runtime.onInstalled.addListener(function () {
chrome.contextMenus.removeAll(function () {
chrome.contextMenus.create({
id: "freediumRedirect",
title: "Open with Freedium",
contexts: ["page", "link"],
documentUrlPatterns: ["*://*.medium.com/*"],
targetUrlPatterns: ["*://*.medium.com/*"]
});
});
});
chrome.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === "freediumRedirect") {
let targetUrl = tab.url;
if (info.linkUrl) {
targetUrl = info.linkUrl;
}
const newUrl = "https://freedium.cfd/" + targetUrl.replace("https://", "");
chrome.tabs.update(tab.id, { url: newUrl });
}
});
chrome.action.onClicked.addListener(function (tab) {
if (tab.url.includes("medium.com")) {
const newUrl = "https://freedium.cfd/" + tab.url.replace("https://", "");
chrome.tabs.update(tab.id, { url: newUrl });
}
});