- Joined
- Aug 27, 2024
- Messages
- 1
- Reaction score
- 0
Hi folks,
I need your help. (Sorry for my English, it's not my native language.)
My problem:
I want to create an add-on that allows me to enter several words in the Twitch chat.
Currently, thanks to ChatGPT, I have made it so that the add-on presses the “Rewards & PowerUps” button when a word “XY” is successfully found in the Twitch chat, then it waits 1 second and then presses the desired button XY (currently “Highlight my messages”).
1. the desired Twitch page is created.
2. waits 3-5 sec
3. searches for a term that appears NEW “XY” (Currently he is looking for the word “WILDNESS” which is currently only a placeholder, because the word is on the desired page and to check whether all further steps work, he logically has to find the word. In the right case, it is such a difficult word that it cannot be written beforehand by chance, so it cannot find it beforehand. So that shouldn't be the problem).
4. Word was found, so he presses button 1:
5. wait 1 second
6. now press button 2:
7. now we are at the problem, actually only some text, word, letter should be here:
be inserted and sent.
That would be it. But I'm stuck on the last point.
Let's not forget, as I said, that everything should only happen ONCE xD. Don't want to spam haha.
See here what i have (Javascript):
And this is where my problem begins.
Because now you have to enter something in the text field so that you can send it:
The funny thing is, ChatGPT has got it so far that it doesn't send anything the first time, but the second time and then every time with this text:
But this is obviously wrong xD. Apart from the fact that it should only do everything once.
But since no ChatGPT can fix it either, I'll ask here.
I would be grateful for any help.
Even if it could be done differently.
Thank you very much
Greetings
I need your help. (Sorry for my English, it's not my native language.)
My problem:
I want to create an add-on that allows me to enter several words in the Twitch chat.
Currently, thanks to ChatGPT, I have made it so that the add-on presses the “Rewards & PowerUps” button when a word “XY” is successfully found in the Twitch chat, then it waits 1 second and then presses the desired button XY (currently “Highlight my messages”).
1. the desired Twitch page is created.
2. waits 3-5 sec
3. searches for a term that appears NEW “XY” (Currently he is looking for the word “WILDNESS” which is currently only a placeholder, because the word is on the desired page and to check whether all further steps work, he logically has to find the word. In the right case, it is such a difficult word that it cannot be written beforehand by chance, so it cannot find it beforehand. So that shouldn't be the problem).
4. Word was found, so he presses button 1:
5. wait 1 second
6. now press button 2:
7. now we are at the problem, actually only some text, word, letter should be here:
be inserted and sent.
That would be it. But I'm stuck on the last point.
Let's not forget, as I said, that everything should only happen ONCE xD. Don't want to spam haha.
See here what i have (Javascript):
JavaScript:
function checkForBot() {
console.log("Check for WILDNESS");
const botText = document.body.innerText;
if (botText.includes("WILDNESS")) {
console.log("WILDNESS was found");
// Carry out the first action (Click button)
const firstButtonSelector =
"#live-page-chat > div > div > div.Layout-sc-1xcs6mc-0.iTiPMO.chat-shell.chat-shell__expanded > div > div > section > div > div.Layout-sc-1xcs6mc-0.kILIqT.chat-input > div:nth-child(2) > div.Layout-sc-1xcs6mc-0.eWfUfi.chat-input__buttons-container > div.Layout-sc-1xcs6mc-0.cNKHwD > div > div > div > div.Layout-sc-1xcs6mc-0.iVvsmg > div.InjectLayout-sc-1i43xsx-0.kBtJDm > button";
const firstButton = document.querySelector(firstButtonSelector);
if (firstButton) {
firstButton.click();
console.log("First button pressed");
// Wait 1 second and perform the second action
setTimeout(() => {
const rewardButtonSelector =
"#channel-points-reward-center-body > div > div > div:nth-child(8) > div > button";
const rewardButton = document.querySelector(rewardButtonSelector);
if (rewardButton) {
rewardButton.click();
console.log("DONE");
// Paste the desired text into the chat and send it
sendChatMessage("RANDOM TEXT, LETTER or number");
} else {
console.error("Reward button not found");
}
}, 1000); // Wait 1 second
} else {
console.error("First button not found");
}
}
}
function sendChatMessage(message) {
// Find the chat input field
const chatInput = document.querySelector('[data-a-target="chat-input"]');
if (!chatInput) {
console.error("Chat input field not found");
return;
}
// Create the content for the input field
const content = `<div data-slate-node="element"><span data-slate-node="text"><span data-slate-leaf="true" class="ScTransitionBase-sc-hx4quq-0 iEzfDB tw-transition" data-a-target="chat-input-text" aria-hidden="false"><span data-slate-string="true">${message}</span></span></span></div>`;
// Set the content of the input field
chatInput.innerHTML = content;
// Create and dispatch an input event
const inputEvent = new InputEvent("input", {
bubbles: true,
cancelable: true,
});
chatInput.dispatchEvent(inputEvent);
// Find the send button
const sendButton = document.querySelector(
'[data-a-target="chat-send-button"]'
);
if (!sendButton) {
console.error("Send button not found");
return;
}
// Click on the Send button
sendButton.click();
}
// Use the function to send a message
sendChatMessage("RANDOM TEXT, LETTER or number");
window.addEventListener("load", () => {
setTimeout(() => {
setInterval(checkForBot, 5000); // Checks every 5 seconds
}, 1000); // Waits 1 second after loading the page
});
Because now you have to enter something in the text field so that you can send it:
The funny thing is, ChatGPT has got it so far that it doesn't send anything the first time, but the second time and then every time with this text:
JavaScript:
`<div data-slate-node="element"><span data-slate-node="text"><span data-slate-leaf="true" class="ScTransitionBase-sc-hx4quq-0 iEzfDB tw-transition" data-a-target="chat-input-text" aria-hidden="false"><span data-slate-string="true">${message}</span></span></span></div>`;
But since no ChatGPT can fix it either, I'll ask here.
I would be grateful for any help.
Even if it could be done differently.
Thank you very much
Greetings