manifest v3

This commit is contained in:
Rpsl 2021-07-26 19:19:34 +03:00
parent e2ea7a7378
commit 7c68f691d8
2 changed files with 27 additions and 18 deletions

View File

@ -22,24 +22,35 @@ chrome.contextMenus.onClicked.addListener(function (item, tab) {
}
let url = data.metube;
let xhr = new XMLHttpRequest();
xhr.open("POST", url + "/add", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
let json = JSON.parse(xhr.responseText);
if (json.status === "ok") {
fetch(url + "/add", {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"quality": "best", "url": item.linkUrl})
})
.then(function (res) {
if (res.ok === true && res.status === 200) {
return res.json();
}
alert("error :: code " + res.status);
})
.then(function (result) {
if (result.status === "ok") {
openTab(data.metube, tab);
} else {
alert("error :: " + json);
}
}
};
xhr.send(JSON.stringify({"quality": "best", "url": item.linkUrl}));
})
.catch(function (res) {
alert("error :: " + res);
})
});
});
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.action.onClicked.addListener(function (tab) {
chrome.storage.sync.get(['metube'], function (data) {
if (data === undefined || !data.hasOwnProperty('metube') || data.metube === "") {
openTab(chrome.extension.getURL('options.html'), tab);
@ -53,7 +64,8 @@ chrome.browserAction.onClicked.addListener(function (tab) {
function openTab(url, currentTab) {
chrome.tabs.query({url: url + "/*"}, function (tabs) {
if (tabs.length !== 0) {
chrome.tabs.update(tabs[0].id, {'active': true}, () => {});
chrome.tabs.update(tabs[0].id, {'active': true}, () => {
});
} else {
chrome.tabs.create({url: url, index: currentTab.index + 1});
}

View File

@ -2,19 +2,16 @@
"name": "MeTube Downloader",
"description": "Use the context menu to send video into MeTube application",
"version": "1.0",
"manifest_version": 2,
"manifest_version": 3,
"permissions": ["contextMenus", "storage", "tabs"],
"background": {
"scripts": [
"background.js"
],
"persistent": false
"service_worker": "background.js"
},
"options_ui": {
"page": "options.html",
"browser_style": true
},
"browser_action": {
"action": {
"default_title": "",
"default_icon": "icon128.png"
},