diff --git a/background.js b/background.js deleted file mode 100644 index ad1c29a..0000000 --- a/background.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -chrome.browserAction.onClicked.addListener(function(callback) { - //chrome.declarativeContent.ShowPageAction(); -}); - -chrome.runtime.onInstalled.addListener(function() { -// chrome.storage.sync.set({color: '#3aa757'}, function() { -// console.log("The color is green."); -// }); -}); diff --git a/common_content_script.js b/common_content_script.js index 332c840..c531d7e 100644 --- a/common_content_script.js +++ b/common_content_script.js @@ -17,8 +17,7 @@ function twitterXPath(nth, sendResponse) { sendResponse({dataType: 'urlList', urlList: arr, source: window.location.href}); } -chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { - +chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { if (request.action == "requestPics") { twitterXPath(1, sendResponse); } else if (request.action == "requestPics2") { @@ -28,6 +27,6 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { } else if (request.action == "requestPics4") { twitterXPath(4, sendResponse); } else { - sendResponse({}); // Send nothing.. + sendResponse({dataType: 'test'}); // Send nothing.. } }); diff --git a/icon.jpg b/icon.jpg new file mode 100644 index 0000000..cb9c3ef Binary files /dev/null and b/icon.jpg differ diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..f933d04 Binary files /dev/null and b/icon.png differ diff --git a/manifest.json b/manifest.json index ef50511..2e026a8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,22 +1,21 @@ { + "manifest_version": 3, "name": "Download The Pics (WebExtension Client)", - "version": "1.0", - "manifest_version": 2, "description": "Download The Pics WebExtension Client. You also need the local daemon process to make this extension works", - "background": { - "scripts": ["background.js"] + "version": "2.0", + "icons": { + "48": "icon.png" }, - "browser_action": { - "default_popup": "popup.html" + "permissions": ["activeTab", "declarativeContent"], + "action": { + "default_popup": "popup.html", + "default_icon": "icon.png" }, "content_scripts": [ - { - "matches": [""], - "run_at": "document_start", - "js": ["common_content_script.js"] - } - ], - "permissions": [ - "activeTab", "declarativeContent" + { + "matches": [""], + "run_at": "document_start", + "js": ["common_content_script.js"] + } ] } diff --git a/popup.html b/popup.html index 3e45c56..a184682 100644 --- a/popup.html +++ b/popup.html @@ -11,10 +11,9 @@ -
- - - + + + diff --git a/popup.js b/popup.js index 694ab62..3841928 100644 --- a/popup.js +++ b/popup.js @@ -9,9 +9,9 @@ let download4Btn = document.getElementById('download4'); // }); function sendActionAndResponse(actionStr) { - chrome.tabs.getSelected(null, function(tab) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { // Send a request to the content script. - chrome.tabs.sendRequest(tab.id, {action: actionStr}, function(response) { + chrome.tabs.sendMessage(tabs[0].id, {action: actionStr}, (response) => { console.log(response); if (response.dataType == "urlList") { const data = new URLSearchParams(); @@ -24,6 +24,8 @@ function sendActionAndResponse(actionStr) { }).then(data => { console.log(data); }); + } else { + console.log(response.dataType) } }); });