refactor: port to manifest v3

This commit is contained in:
Gary Wang 2024-06-03 22:50:19 +08:00
parent 4741eeabee
commit 1921d0e626
7 changed files with 22 additions and 34 deletions

View File

@ -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.");
// });
});

View File

@ -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..
}
});

BIN
icon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -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": ["<all_urls>"],
"run_at": "document_start",
"js": ["common_content_script.js"]
}
],
"permissions": [
"activeTab", "declarativeContent"
{
"matches": ["<all_urls>"],
"run_at": "document_start",
"js": ["common_content_script.js"]
}
]
}

View File

@ -11,10 +11,9 @@
</head>
<body>
<button id="download">Download</button>
<br/>
<button id="download2">2nd</button>
<button id="download3">3rd</button>
<button id="download4">4th</button>
<button id="download2">2nd</button>
<button id="download3">3rd</button>
<button id="download4">4th</button>
<script src="popup.js"></script>
</body>
</html>

View File

@ -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)
}
});
});