forked from meeeejin/srtmacro
-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
38 lines (34 loc) · 1.08 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
function playSound() {
if (typeof(audio) != "undefined" && audio) {
audio.pause();
document.body.removeChild(audio);
audio = null;
}
audio = document.createElement('audio');
document.body.appendChild(audio);
audio.autoplay = true;
audio.src = chrome.runtime.getURL('assets/tada.mp3');
audio.play();
}
function sendTelegramMessage(botToken, chatId) {
var msg = encodeURI('Macro has been stopped. Please check your reservation status.');
if (botToken != undefined && chatId != undefined) {
var url = 'https://api.telegram.org/bot' + botToken + '/sendmessage?chat_id=' + chatId + '&text=' + msg;
fetch(url);
}
}
var botToken;
var chatId;
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message && message.type == 'playSound') {
// cannot play sound in service_worker from Manifest v3
//playSound();
sendTelegramMessage(botToken, chatId);
sendResponse(true);
}
if (message && message.type == 'setTelegram') {
botToken = message.botToken;
chatId = message.chatId;
console.log('botToken: ', botToken);
}
});