OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Automation of joining groups in telegram channels giving FCFS links

  • Thread starter Thread starter Lucky Rajput
  • Start date Start date
L

Lucky Rajput

Guest
This is my VioletMonkey script the problem I am facing is that it clicks invite link but after that nothing happens not logging in console

like after inviteLink.click() the console.log('Proceeding Further') isnt getting logged which means script isn't doing further interaction

Code:
// ==UserScript==
// @name         Telegram Invite Link Auto Clicker
// @namespace    Violentmonkey Scripts
// @version      1.0
// @description  Automatically click Telegram invite links when they are posted in a specific chat channel and join the group
// @author       Your Name
// @match        https://web.telegram.org/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const TARGET_CHANNEL = 'https://web.telegram.org/k/#-2159974321';

    async function setupMutationObserver() {
        const observer = new MutationObserver((mutationsList, observer) => {
            mutationsList.forEach(mutation => {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains('message')) {
                        processMessageContainer(node);
                    }
                });
            });
        });

        const body = document.body;

        if (body) {
            observer.observe(body, { childList: true, subtree: true });
            console.log('Telegram Invite Link Auto Clicker started.');
        } else {
            console.error('Document body not found.');
        }
    }

    async function processMessageContainer(messageContainer) {
        const inviteLink = messageContainer.querySelector('.anchor-url');
        const channelLink = getChannelLink(messageContainer);

        if (inviteLink && channelLink === TARGET_CHANNEL) {
            console.log('New invite link detected in channel:', channelLink);
            console.log('Invite link detected:', inviteLink.href);
            inviteLink.click();
            console.log('Proceeding Further')
            waitForPopupAndClickJoinGroup();
        }
    }

    async function waitForPopupAndClickJoinGroup() {
        console.log('Waiting for popup to appear...');
        const popupElement = await waitForElement('.popup.popup-peer.popup-join-chat-invite.active');
        
        if (popupElement) {
            console.log('Popup element found. Clicking Join Group button...');
            const joinGroupButton = popupElement.querySelector('.popup-button.btn.primary.rp .i18n');
            if (joinGroupButton && joinGroupButton.textContent.trim() === 'Join Group') {
                console.log('Join Group button found. Clicking...');
                joinGroupButton.click();
            } else {
                console.log('Join Group button not found or does not contain expected text.');
            }
        } else {
            console.log('Popup element not found.');
        }
    }

    function getChannelLink(messageContainer) {
        const channelLinkElement = messageContainer.querySelector('.peer a');
        return channelLinkElement ? channelLinkElement.href : '';
    }

    async function waitForElement(selector, timeout = 10000) {
        return new Promise((resolve, reject) => {
            const startTime = Date.now();
            const interval = setInterval(() => {
                const element = document.querySelector(selector);
                if (element) {
                    clearInterval(interval);
                    resolve(element);
                } else if (Date.now() - startTime >= timeout) {
                    clearInterval(interval);
                    reject(new Error(`Timeout waiting for element with selector: ${selector}`));
                }
            }, 500);
        });
    }

    function delay(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }

    document.addEventListener('DOMContentLoaded', () => {
        setupMutationObserver();
    });

})();

Expecting to automate the group joining by making script to execute further steps after invite link clicked

<p>This is my VioletMonkey script the problem I am facing is that it clicks invite link but after that nothing happens not logging in console</p>
<p>like after inviteLink.click() the console.log('Proceeding Further') isnt getting logged which means script isn't doing further interaction</p>
<pre><code>
// ==UserScript==
// @name Telegram Invite Link Auto Clicker
// @namespace Violentmonkey Scripts
// @version 1.0
// @description Automatically click Telegram invite links when they are posted in a specific chat channel and join the group
// @author Your Name
// @match https://web.telegram.org/*
// @grant none
// ==/UserScript==

(function() {
'use strict';

const TARGET_CHANNEL = 'https://web.telegram.org/k/#-2159974321';

async function setupMutationObserver() {
const observer = new MutationObserver((mutationsList, observer) => {
mutationsList.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains('message')) {
processMessageContainer(node);
}
});
});
});

const body = document.body;

if (body) {
observer.observe(body, { childList: true, subtree: true });
console.log('Telegram Invite Link Auto Clicker started.');
} else {
console.error('Document body not found.');
}
}

async function processMessageContainer(messageContainer) {
const inviteLink = messageContainer.querySelector('.anchor-url');
const channelLink = getChannelLink(messageContainer);

if (inviteLink && channelLink === TARGET_CHANNEL) {
console.log('New invite link detected in channel:', channelLink);
console.log('Invite link detected:', inviteLink.href);
inviteLink.click();
console.log('Proceeding Further')
waitForPopupAndClickJoinGroup();
}
}

async function waitForPopupAndClickJoinGroup() {
console.log('Waiting for popup to appear...');
const popupElement = await waitForElement('.popup.popup-peer.popup-join-chat-invite.active');

if (popupElement) {
console.log('Popup element found. Clicking Join Group button...');
const joinGroupButton = popupElement.querySelector('.popup-button.btn.primary.rp .i18n');
if (joinGroupButton && joinGroupButton.textContent.trim() === 'Join Group') {
console.log('Join Group button found. Clicking...');
joinGroupButton.click();
} else {
console.log('Join Group button not found or does not contain expected text.');
}
} else {
console.log('Popup element not found.');
}
}

function getChannelLink(messageContainer) {
const channelLinkElement = messageContainer.querySelector('.peer a');
return channelLinkElement ? channelLinkElement.href : '';
}

async function waitForElement(selector, timeout = 10000) {
return new Promise((resolve, reject) => {
const startTime = Date.now();
const interval = setInterval(() => {
const element = document.querySelector(selector);
if (element) {
clearInterval(interval);
resolve(element);
} else if (Date.now() - startTime >= timeout) {
clearInterval(interval);
reject(new Error(`Timeout waiting for element with selector: ${selector}`));
}
}, 500);
});
}

function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

document.addEventListener('DOMContentLoaded', () => {
setupMutationObserver();
});

})();

</code></pre>
<p>Expecting to automate the group joining by making script to execute further steps after invite link clicked</p>
 
Top