Jul 18, 2023 08:11 AM
(This post was last modified: Jul 18, 2023 01:52 PM by Mr. Robot.)
Was just testing some stuff and came up with this.
Could easily implement avatars, etc but was just wanting to test it.
IMPORTANT. It doesn't abuse HF. Right now it just uses your browser session and every time it gets a new message in convo sends it to the discord webhook.
![[Image: kfSAzzA.gif]](https://i.imgur.com/kfSAzzA.gif)
Any javascript geniuses wanna make it work for double posts by a user and implement avatars for the bots you can do it. Here is the code. I give up.
1. Install tamper monkey in your browser.
2. Add the below code to tamper monkey.
3. Go to discord and make a server.
4. In server settings in discord click on Apps > Integrations > Webhoooks.
5. Paste that URL for the webhook into the tamper monkey script.
6. Go to the convo page in your browser and it will begin.
>> Notes:
1. It will already take URLs of images people post and embedd them nicely.
2. When someone uploads an image to chat it will be a base string which you can convert
3. Discord supports changing the bots avatars via the request so you can make it more realistic.
Maybe this will inspire you to use tampermonkey for web based projects into the discord hook - you'd just need a server on that website/page to do it. Or a tab on your browser accessing the site. Even then you technically don't have to if you tamper monkey every site you visit with an iframe of the site you are scraping etc etc but don't do that, that's naughty.
Could easily implement avatars, etc but was just wanting to test it.
IMPORTANT. It doesn't abuse HF. Right now it just uses your browser session and every time it gets a new message in convo sends it to the discord webhook.
![[Image: kfSAzzA.gif]](https://i.imgur.com/kfSAzzA.gif)
Any javascript geniuses wanna make it work for double posts by a user and implement avatars for the bots you can do it. Here is the code. I give up.
1. Install tamper monkey in your browser.
2. Add the below code to tamper monkey.
3. Go to discord and make a server.
4. In server settings in discord click on Apps > Integrations > Webhoooks.
5. Paste that URL for the webhook into the tamper monkey script.
6. Go to the convo page in your browser and it will begin.
Code
// ==UserScript==
// @name HackForums Chat
// @version 1
// @grant none
// @match https://hackforums.net/convo.php
// ==/UserScript==
(function() {
'use strict';
const WEBHOOK_URL = 'WEBHOOKGOESHERE';
let lastUid = null;
let lastUsername = null;
function fetchLatestMessages() {
let allMessages = Array.from(document.querySelectorAll('.message-convo-left, .message-convo-right'));
let newMessages = [];
for (let i = allMessages.length - 1; i >= 0; i--) {
if (allMessages[i].getAttribute('data-uid') !== lastUid) {
newMessages.unshift(allMessages[i]);
} else {
break;
}
}
return newMessages;
}
function sendToWebhook(username, message) {
fetch(WEBHOOK_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: username,
content: message,
}),
}).catch((error) => {
console.error(`Error sending message to webhook: ${error}`);
});
}
setInterval(() => {
let latestMessages = fetchLatestMessages();
for (let latestMessage of latestMessages) {
let currentUid = latestMessage.getAttribute('data-uid');
let usernameDiv = latestMessage.querySelector('.message-bubble-left a');
let usernameFromAvatar = latestMessage.querySelector('.mirum-card-profile-info-username a span');
let username;
if (latestMessage.classList.contains('message-convo-right')) {
username = "Mr. Robot";
} else if (usernameDiv) {
username = usernameDiv.textContent.trim();
lastUsername = username; // Save the username for further use
} else if (usernameFromAvatar) {
username = usernameFromAvatar.textContent.trim();
lastUsername = username; // Save the username for further use
} else if (currentUid === lastUid && lastUsername) {
username = lastUsername;
} else {
console.log("Could not find username for message: ", latestMessage);
continue;
}
let messageDiv = latestMessage.querySelector('.message-bubble-message');
if (messageDiv) {
let message = messageDiv.textContent.trim();
console.log(`New message from ${username}: ${message}`);
sendToWebhook(username, message);
}
lastUid = currentUid;
}
}, 100);
})();>> Notes:
1. It will already take URLs of images people post and embedd them nicely.
2. When someone uploads an image to chat it will be a base string which you can convert
3. Discord supports changing the bots avatars via the request so you can make it more realistic.
Maybe this will inspire you to use tampermonkey for web based projects into the discord hook - you'd just need a server on that website/page to do it. Or a tab on your browser accessing the site. Even then you technically don't have to if you tamper monkey every site you visit with an iframe of the site you are scraping etc etc but don't do that, that's naughty.



![[Image: IMK3P8b6_o.png]](https://images2.imgbox.com/85/09/IMK3P8b6_o.png)


