-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
51 lines (41 loc) · 1.58 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
chrome.contextMenus.create({
id: 'zservdownloader',
title: 'Downlaod with ZDownloadChrome',
contexts: ['selection'],
});
chrome.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === 'zservdownloader') {
console.log(info.selectionText);
// Récupération de l'URL externe depuis le stockage local
chrome.storage.local.get(['externalUrl'], function (result) {
const externalUrl = result.externalUrl;
if (externalUrl) {
const selectedText = info.selectionText;
const urlWithText = externalUrl.replace('{{notre_texte}}', encodeURIComponent(selectedText));
var urls = {urls: selectedText.split(" ")};
console.log(urls);
fetch(urlWithText, {
method: 'POST',
body: JSON.stringify(urls),
}).then(function (response) {
return response.json();
}).then(function (data) {
});
//open the popup
chrome.windows.create({
url: 'popup.html',
type: 'popup',
width: 800,
height: 600
}, function (window) {
//window is the newly opened window
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === "getSelectedText") {
sendResponse({ selectedText: selectedText });
}
});
});
}
});
}
});