-
Notifications
You must be signed in to change notification settings - Fork 0
/
content-script.js
39 lines (34 loc) · 1.14 KB
/
content-script.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
// Get username and webhook from storage
function LogCurrentPage() {
chrome.runtime.sendMessage('get-data', (response) => {
console.log('received user data', response);
// Create a message object
const params = {
username: "Youtube Logger",
avatar_url: "",
content: response.username + " started watching [this](" + window.location.href + ") at " + new Date().toLocaleString()
}
// Send message to webhook
fetch(response.webhook, {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params)
})
});
}
// Log page only when it's a video
if (window.location.href.includes("youtube.com/watch?")) {
LogCurrentPage();
}
// Track page changes
let currentSite = window.location.href
setInterval(function () {
if (currentSite != window.location.href) {
if (window.location.href.includes("youtube.com/watch?")) {
LogCurrentPage();
}
currentSite = window.location.href;
}
}, 1000);