Skip to content

Commit 5ea88ff

Browse files
committed
Add context menu on extension icon
1 parent ea26e55 commit 5ea88ff

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

js/background.js

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
importScripts('utilities.js');
32
importScripts('functions.js');
43

@@ -11,7 +10,7 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
1110
// updateIcon(tabId);
1211
});
1312

14-
function updateIcon(tabId) {
13+
async function updateIcon(tabId) {
1514
chrome.tabs.get(tabId, function(change){
1615

1716
chrome.tabs.get(tabId, function(tab){
@@ -35,4 +34,82 @@ function updateIcon(tabId) {
3534
});
3635
});
3736
});
38-
};
37+
};
38+
39+
async function removeAllContextMenus() {
40+
return new Promise((resolve) => {
41+
chrome.contextMenus.removeAll(() => {
42+
resolve();
43+
});
44+
});
45+
}
46+
47+
async function createActionContextMenus() {
48+
await removeAllContextMenus();
49+
50+
chrome.contextMenus.create({
51+
id: "support",
52+
title: "❤️ Support",
53+
contexts: ["action"]
54+
});
55+
56+
chrome.contextMenus.create({
57+
id: "issues",
58+
title: "🤔 Issues and Suggestions",
59+
contexts: ["action"]
60+
});
61+
62+
chrome.contextMenus.create({
63+
id: "github",
64+
title: "🌐 GitHub",
65+
parentId: "issues",
66+
contexts: ["action"]
67+
});
68+
69+
chrome.contextMenus.create({
70+
id: "reportIssue",
71+
title: "🐛 Report Issue",
72+
parentId: "issues",
73+
contexts: ["action"]
74+
});
75+
76+
// Sous-menus de "Support"
77+
chrome.contextMenus.create({
78+
id: "donate",
79+
title: "🍕 Buy me a pizza",
80+
parentId: "support",
81+
contexts: ["action"]
82+
});
83+
84+
chrome.contextMenus.create({
85+
id: "review",
86+
title: "🌟 Leave a review",
87+
parentId: "support",
88+
contexts: ["action"]
89+
});
90+
}
91+
92+
chrome.runtime.onInstalled.addListener(async () => {
93+
await createActionContextMenus();
94+
});
95+
96+
chrome.runtime.onStartup.addListener(async () => {
97+
await createActionContextMenus();
98+
});
99+
100+
chrome.contextMenus.onClicked.addListener(async (info, tab) => {
101+
switch (info.menuItemId) {
102+
case "github":
103+
chrome.tabs.create({ url: 'https://github.com/shevabam/get-rss-feed-url-extension' });
104+
break;
105+
case "reportIssue":
106+
chrome.tabs.create({ url: 'https://github.com/shevabam/get-rss-feed-url-extension/issues' });
107+
break;
108+
case "donate":
109+
chrome.tabs.create({ url: 'https://buymeacoffee.com/shevabam' });
110+
break;
111+
case "review":
112+
chrome.tabs.create({ url: `https://chromewebstore.google.com/detail/${chrome.runtime.id}/reviews` });
113+
break;
114+
}
115+
});

js/functions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ function getGithubRepoRss(url) {
437437

438438
let regex = /^(http(s)?:\/\/)?((w){3}.)?github\.com\/([a-zA-Z0-9](.+))\/([a-zA-Z0-9](.+))$/i;
439439
let matches = url.match(regex);
440-
console.log(matches);
441440

442441
if (matches) {
443442
datas.match = true;

manifest.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"homepage_url": "https://github.com/shevabam/get-rss-feed-url-extension",
88
"permissions": [
99
"activeTab",
10-
"notifications"
10+
"notifications",
11+
"contextMenus"
1112
],
1213
"host_permissions": [
1314
"http://*/*",
@@ -21,6 +22,9 @@
2122
"icons": {
2223
"128" : "img/icon_128.png"
2324
},
25+
"background": {
26+
"service_worker": "js/background.js"
27+
},
2428
"commands": {
2529
"_execute_action": {
2630
"suggested_key": {

0 commit comments

Comments
 (0)