From 424c33fec50a94977c0d658269756f4d461ef9ca Mon Sep 17 00:00:00 2001 From: Sol Ha Date: Fri, 27 Oct 2017 16:46:30 +0900 Subject: [PATCH] =?UTF-8?q?*=20=ED=85=94=EB=A0=88=EA=B7=B8=EB=9E=A8=20?= =?UTF-8?q?=EB=B4=87=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20=20=20-?= =?UTF-8?q?=20=ED=99=95=EC=9E=A5=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=A8?= =?UTF-8?q?=EC=9D=98=20'=EC=98=B5=EC=85=98'=EC=97=90=EC=84=9C=20=ED=85=94?= =?UTF-8?q?=EB=A0=88=EA=B7=B8=EB=9E=A8=20=EB=B4=87=EC=9D=98=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0(token)=EA=B3=BC=20=EB=B3=B8=EC=9D=B8=EC=9D=98=20chat?= =?UTF-8?q?=20id=20=EC=84=A4=EC=A0=95=20=EA=B0=80=EB=8A=A5,=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=A0=80=EC=9E=A5=20=EC=8B=9C=20'Bot=20connected.'?= =?UTF-8?q?=20=EB=9D=BC=EB=8A=94=20=EB=A9=94=EC=8B=9C=EC=A7=80=EA=B0=80=20?= =?UTF-8?q?=EB=B4=87=EC=97=90=EA=B2=8C=20=EC=A0=84=EB=8B=AC=EB=90=A8=20=20?= =?UTF-8?q?=20-=20=EC=98=88=EC=95=BD=20=EC=99=84=EB=A3=8C=20=EC=8B=9C=20?= =?UTF-8?q?=ED=8A=B8=EB=9F=BC=ED=8E=AB=20=EC=86=8C=EB=A6=AC=EC=99=80=20?= =?UTF-8?q?=ED=95=A8=EA=BB=98=20=ED=85=94=EB=A0=88=EA=B7=B8=EB=9E=A8=20?= =?UTF-8?q?=EB=B4=87=EC=9C=BC=EB=A1=9C=20=EC=98=88=EC=95=BD=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=20=EC=95=8C=EB=A6=AC=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background.js | 19 +++++++++++++++++++ manifest.json | 6 +++++- options.html | 29 +++++++++++++++++++++++++++++ options.js | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 options.html create mode 100644 options.js diff --git a/background.js b/background.js index c454cf2..e47ac28 100644 --- a/background.js +++ b/background.js @@ -11,9 +11,28 @@ function playSound() { audio.play(); } +function sendTelegramMessage() { + var botToken = localStorage['botToken']; + var chatId = localStorage['chatId']; + var msg = encodeURI('Succeeded in booking a train ticket.'); + 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); } }); \ No newline at end of file diff --git a/manifest.json b/manifest.json index 9ada20b..3e516cf 100644 --- a/manifest.json +++ b/manifest.json @@ -20,5 +20,9 @@ }, "web_accessible_resources": [ "inject.js", "images/btn_start.png", "images/btn_stop.png", "assets/tada.mp3" - ] + ], + "options_ui": { + "page": "options.html", + "chrome_style": true + } } diff --git a/options.html b/options.html new file mode 100644 index 0000000..f97f047 --- /dev/null +++ b/options.html @@ -0,0 +1,29 @@ + + + + SRT Macro Options + + + + + + + + + + + + + +
Bot Token:
Your Telegram Chat ID:
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/options.js b/options.js new file mode 100644 index 0000000..3d2b5b3 --- /dev/null +++ b/options.js @@ -0,0 +1,41 @@ +var defaultBotToken = 'Set your telegram bot token'; +var defaultChatId = 'Set your telegram chat id'; + +function save_options() { + localStorage['botToken'] = document.getElementById('bot_token').value; + localStorage['chatId'] = document.getElementById('chat_id').value; + + var url = 'https://api.telegram.org/bot' + document.getElementById('bot_token').value + '/sendmessage?chat_id=' + document.getElementById('chat_id').value + '&text=' + encodeURI('Bot connected.'); + + 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(); + + var status = document.getElementById('status'); + status.textContent = 'Options saved.'; + setTimeout(function() { + status.textContent = ''; + }, 750); +} + +function restore_options() { + var botToken = localStorage['botToken']; + var chatId = localStorage['chatId']; + + if (botToken == undefined) + botToken = defaultBotToken; + + if (chatId == undefined) + chatId = defaultChatId; + + document.getElementById('bot_token').value = botToken; + document.getElementById('chat_id').value = chatId; +} +document.addEventListener('DOMContentLoaded', restore_options); +document.getElementById('save').addEventListener('click', + save_options); \ No newline at end of file