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

View File

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