refactor: port to manifest v3
This commit is contained in:
parent
4741eeabee
commit
1921d0e626
@ -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.");
|
|
||||||
// });
|
|
||||||
});
|
|
@ -17,8 +17,7 @@ function twitterXPath(nth, sendResponse) {
|
|||||||
sendResponse({dataType: 'urlList', urlList: arr, source: window.location.href});
|
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") {
|
if (request.action == "requestPics") {
|
||||||
twitterXPath(1, sendResponse);
|
twitterXPath(1, sendResponse);
|
||||||
} else if (request.action == "requestPics2") {
|
} else if (request.action == "requestPics2") {
|
||||||
@ -28,6 +27,6 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
|
|||||||
} else if (request.action == "requestPics4") {
|
} else if (request.action == "requestPics4") {
|
||||||
twitterXPath(4, sendResponse);
|
twitterXPath(4, sendResponse);
|
||||||
} else {
|
} else {
|
||||||
sendResponse({}); // Send nothing..
|
sendResponse({dataType: 'test'}); // Send nothing..
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
{
|
{
|
||||||
|
"manifest_version": 3,
|
||||||
"name": "Download The Pics (WebExtension Client)",
|
"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",
|
"description": "Download The Pics WebExtension Client. You also need the local daemon process to make this extension works",
|
||||||
"background": {
|
"version": "2.0",
|
||||||
"scripts": ["background.js"]
|
"icons": {
|
||||||
|
"48": "icon.png"
|
||||||
},
|
},
|
||||||
"browser_action": {
|
"permissions": ["activeTab", "declarativeContent"],
|
||||||
"default_popup": "popup.html"
|
"action": {
|
||||||
|
"default_popup": "popup.html",
|
||||||
|
"default_icon": "icon.png"
|
||||||
},
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": ["<all_urls>"],
|
"matches": ["<all_urls>"],
|
||||||
"run_at": "document_start",
|
"run_at": "document_start",
|
||||||
"js": ["common_content_script.js"]
|
"js": ["common_content_script.js"]
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"permissions": [
|
|
||||||
"activeTab", "declarativeContent"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<button id="download">Download</button>
|
<button id="download">Download</button>
|
||||||
<br/>
|
<button id="download2">2nd</button>
|
||||||
<button id="download2">2nd</button>
|
<button id="download3">3rd</button>
|
||||||
<button id="download3">3rd</button>
|
<button id="download4">4th</button>
|
||||||
<button id="download4">4th</button>
|
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
6
popup.js
6
popup.js
@ -9,9 +9,9 @@ let download4Btn = document.getElementById('download4');
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
function sendActionAndResponse(actionStr) {
|
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.
|
// 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);
|
console.log(response);
|
||||||
if (response.dataType == "urlList") {
|
if (response.dataType == "urlList") {
|
||||||
const data = new URLSearchParams();
|
const data = new URLSearchParams();
|
||||||
@ -24,6 +24,8 @@ function sendActionAndResponse(actionStr) {
|
|||||||
}).then(data => {
|
}).then(data => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.log(response.dataType)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user