var previousValue = null; function sendTelegramMessage() { // Telegram API settings and sending messages var telegramAPIURL = 'https://api.telegram.org/bot6003449577:AAEPY7N_V7Qw2A0pXTdRd33s7QfMFklWkfg/sendMessage'; // Replace with your Bot Token var chatID = '-794442497'; // Replace with your target chat ID // Getting the text and link from the last HTML element var titleElements = document.querySelectorAll('.structItem-title a'); var lastIndex = titleElements.length - 1; // Index of the last element var message = titleElements[lastIndex].textContent; var link = titleElements[lastIndex].href; if (previousValue !== message) { var data = { chat_id: chatID, text: message, reply_markup: JSON.stringify({ inline_keyboard: [ [ { text: 'Go to Link', url: link } ] ] }) }; // Send message to Telegram using AJAX request fetch(telegramAPIURL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(function (response) { console.log('Message sent to Telegram successfully:', response); }) .catch(function (error) { console.error('Error sending message to Telegram:', error); }); previousValue = message; } else { console.log('No change in value. Message not sent to Telegram.'); } } // Check for changes every 5 seconds setInterval(sendTelegramMessage, 5000);