-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
58 lines (49 loc) · 1.54 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
52
53
54
55
56
const frontendURL ='http://localhost:3000'||'https://app.march.cat.com';
const backendURL ='http://localhost:8080'||'https://sage.march.cat.com';
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: getPageDetails,
}, (results) => {
if (results && results[0].result) {
const { title, url } = results[0].result;
createIssue(title, url);
}
});
});
function getPageDetails() {
return { title: document.title, url: window.location.href };
}
function createIssue(title, url) {
// chrome.cookies.get({ url: 'http://localhost:3000', name: '__MARCH_ACCESS_TOKEN__' }, (cookie) => {
chrome.cookies.get({ url: frontendURL, name: '__MARCH_ACCESS_TOKEN__' }, (cookie) => {
if (cookie) {
// fetch("http://localhost:8080/api/items/create/", {
fetch(`${backendURL}/api/items/create/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${cookie.value}`
},
body: JSON.stringify({
title: title,
source: "marchClipper",
type: "url",
description: url,
metadata: {
url: url
},
})
})
.then(response => response.json())
.then(data => {
console.log('Issue created successfully:', data);
})
.catch(error => {
console.error('Error creating issue:', error);
});
} else {
console.error('No auth token found. Please log in.');
}
});
}