From a363bf7344d441838498e93240140f32391693cf Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 4 Nov 2021 13:31:10 +0100 Subject: [PATCH] feat(scripts): add report context menu item --- scripts/background.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/scripts/background.js b/scripts/background.js index cd35624..ac130f8 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -1,3 +1,9 @@ +/** + * @description Context menu identifier + */ + +const contextMenuId = "CDM_MENU"; + /** * @description Cache initial state * @type {{ enabled: boolean }} @@ -214,6 +220,35 @@ chrome.runtime.onMessage.addListener((request, sender, callback) => { return true; }); +/** + * @description Creates context menu + */ + +chrome.contextMenus.create({ + id: contextMenuId, + title: "Report site...", +}); + +/** + * @description Listens to context menus + */ + +chrome.contextMenus.onClicked.addListener((info, tab) => { + if (info.menuItemId !== contextMenuId) return; + + fetch("https://cdm-report-service.herokuapp.com/rest/v1/report", { + body: JSON.stringify({ + text: tab.url, + to: "wanhose.development@gmail.com", + subject: "Cookie Dialog Monster Report", + }), + headers: { + "Content-type": "application/json", + }, + method: "POST", + }); +}); + /** * @description Listens to updates */