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 a66e408..07162dc 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.runtime.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(); + } + ); + }); + }; +} \ No newline at end of file