forked from meeeejin/srtmacro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
38 lines (35 loc) · 1.16 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.extension.getURL('assets/tada.mp3');
audio.play();
}
function sendTelegramMessage() {
var botToken = localStorage['botToken'];
var chatId = localStorage['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;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var response = xmlhttp.responseText; //if you need to do something with the returned value
}
}
xmlhttp.open('GET', url, true);
xmlhttp.send();
}
}
chrome.extension.onMessage.addListener(function(message, sender, sendResponse) {
if (message && message.type == 'playSound') {
playSound();
sendTelegramMessage();
sendResponse(true);
}
});