-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (63 loc) · 2.23 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
//Function to make the POST request and display the result message from server
const displayTextAlert = () => {
//This param apiURL can be changed if needed
const apiURL = 'https://7l0593rc6k.execute-api.us-east-1.amazonaws.com/details?url='
//POST request to server
const submitURL = async (value) => {
await fetch('https://rocky-beyond-93496.herokuapp.com/'+apiURL+encodeURIComponent(value), {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(r => r.json())
.then(d => {
console.log(d)
let alertElement = `<div id='alertSent'
style='position: fixed;
top: 0px;
width: 100%;
display:flex;
justify-content: center;
z-index:999;
background-color: #00FF00;'>
<h1 style='color: #FFF;'>PAGE SAVED</h1>
</div>`
document.body.innerHTML +=(alertElement)
setTimeout(() => {document.getElementById('alertSent').remove()}, 2000)
})
.catch (err => {
console.log(err)
let alertElement = `<div id='alertSent'
style='position: fixed;
top: 0px;
width: 100%;
display:flex;
justify-content: center;
z-index:999;
background-color: #FF0000;'>
<h1 style='color: #FFF;'>PAGE COULDN'T BE SENT</h1>
</div>`
document.body.innerHTML +=(alertElement)
setTimeout(() => {document.getElementById('alertSent').remove()}, 2000)
})
}
//Executing the function to send the URL
submitURL(window.location.href)
}
//Main function (to execute the script into the active tab)
const catchURL = () => {
chrome.tabs.query({active: true, currentWindow: true}, async (tabs) => {
chrome.scripting.executeScript(
{
target: {tabId: tabs[0].id},
function: displayTextAlert
}
);
})
setTimeout(() => {
window.close()
}, 20);
}
//Call the main function
catchURL()