From 5da4d7bf7694aa215ca9686721f86bd894520b6a Mon Sep 17 00:00:00 2001 From: alexander Date: Wed, 6 Apr 2022 16:36:36 +0200 Subject: [PATCH] Updated the tutorial to Manifest V3 from Manifest V2, because the Manifest version in the tutorial is depricated. --- .../content-scripts/content.js | 4 +- .../lib/jquery.min.js | 4 +- .../manifest.json | 54 ++++++++++--------- .../popup/popup.html | 51 +++++++++--------- .../popup/popup.js | 48 +++++++++-------- 5 files changed, 85 insertions(+), 76 deletions(-) diff --git a/extension-getting-started-part2/extension-getting-started-part2/content-scripts/content.js b/extension-getting-started-part2/extension-getting-started-part2/content-scripts/content.js index e4ee830..1642aed 100644 --- a/extension-getting-started-part2/extension-getting-started-part2/content-scripts/content.js +++ b/extension-getting-started-part2/extension-getting-started-part2/content-scripts/content.js @@ -1,4 +1,4 @@ -chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { +chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { $("head").prepend( ` - - -

Show the NASA Picture of the Day

-

(click on the image to remove)

- - - - + + + + + + + + +

Show the NASA picture of the day

+

(select the image to remove)

+ + + + \ No newline at end of file diff --git a/extension-getting-started-part2/extension-getting-started-part2/popup/popup.js b/extension-getting-started-part2/extension-getting-started-part2/popup/popup.js index 3cb30dc..213305c 100644 --- a/extension-getting-started-part2/extension-getting-started-part2/popup/popup.js +++ b/extension-getting-started-part2/extension-getting-started-part2/popup/popup.js @@ -1,25 +1,27 @@ -const sendMessageId = document.getElementById("sendmessageid"); +const sendMessageId = document.querySelector("#sendMessageId"); if (sendMessageId) { - sendMessageId.onclick = function() { - chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) { - chrome.tabs.sendMessage( - tabs[0].id, - { - url: chrome.extension.getURL("images/stars.jpeg"), - imageDivId: `${guidGenerator()}`, - tabId: tabs[0].id - }, - function(response) { - console.log("message with url sent"); - window.close(); - } - ); - function guidGenerator() { - const S4 = function () { - return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); - }; - return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); - } - }); - }; + sendMessageId.onclick = function () { + chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { + function guidGenerator() { + const S4 = function () { + return (((1 + Math.random()) * 0x10000) | 0) + .toString(16) + .substring(1); + }; + return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); + } + + chrome.tabs.sendMessage( + tabs[0].id, + { + url: chrome.runtime.getURL("images/stars.jpeg"), + imageDivId: `${guidGenerator()}`, + tabId: tabs[0].id, + }, + function (response) { + window.close(); + } + ); + }); + }; }