From a363bf7344d441838498e93240140f32391693cf Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 4 Nov 2021 13:31:10 +0100 Subject: [PATCH 1/3] 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 */ From 5c6d425ab196ac1e70546b6ed709c0430097a11f Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 4 Nov 2021 13:31:28 +0100 Subject: [PATCH 2/3] chore(manifest): upgrade permissions and version --- manifest.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index d326b35..a88744c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Cookie Dialog Monster", - "version": "5.2.1", + "version": "5.3.0", "default_locale": "en", "description": "__MSG_appDesc__", "icons": { @@ -27,6 +27,12 @@ "run_at": "document_start" } ], - "permissions": ["http://*/*", "https://*/*", "storage", "tabs"], + "permissions": [ + "contextMenus", + "http://*/*", + "https://*/*", + "storage", + "tabs" + ], "web_accessible_resources": ["assets/fonts/*", "scripts/*", "styles/*"] } From ca5e27d75927335666c7597ab1076bb5f307e48b Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 4 Nov 2021 14:08:26 +0100 Subject: [PATCH 3/3] fix(scripts): show report option in all contexts --- scripts/background.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/background.js b/scripts/background.js index ac130f8..947fc9e 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -225,6 +225,7 @@ chrome.runtime.onMessage.addListener((request, sender, callback) => { */ chrome.contextMenus.create({ + contexts: ["all"], id: contextMenuId, title: "Report site...", }); @@ -236,7 +237,7 @@ chrome.contextMenus.create({ chrome.contextMenus.onClicked.addListener((info, tab) => { if (info.menuItemId !== contextMenuId) return; - fetch("https://cdm-report-service.herokuapp.com/rest/v1/report", { + fetch("https://cdm-report-service.herokuapp.com/rest/v1/report/", { body: JSON.stringify({ text: tab.url, to: "wanhose.development@gmail.com",