Skip to content

Instantly share code, notes, and snippets.

@robmurrer
Last active February 13, 2024 02:22
Show Gist options
  • Select an option

  • Save robmurrer/d5038f6365a349917551572ca35efcb4 to your computer and use it in GitHub Desktop.

Select an option

Save robmurrer/d5038f6365a349917551572ca35efcb4 to your computer and use it in GitHub Desktop.
campfire botbinder hack
// ==UserScript==
// @name campfire botbinder
// @namespace Violentmonkey Scripts
// @match https://chat.cryptide.com/rooms/*
// @grant none
// @version 1.0
// @author -
// @description 2/12/2024, 9:00:52 AM
// ==/UserScript==
console.log('hi mom')
/** calls a function whenever the DOM changes */
const observeDOM = (fn, e = document.documentElement, config = { attributes: 1, childList: 1, subtree: 1 }) => {
const observer = new MutationObserver(fn);
observer.observe(e, config);
return () => observer.disconnect();
};
const parent_id = "message-area"
function process_bot(response)
{
console.log(JSON.stringify(response))
if (response.some === 101) {
let ib = document.getElementById('message_body')
ib.innerHTML = "<div>" + response.some + " woop --- we are in business!!!! !!! !!!</div>";
document.getElementsByName("send")[0].click()
}
}
function process_chat()
{
//console.log('hi mom, again! ' + new Date())
let m = document.getElementById(parent_id)
//console.log(m)
fetch('http://localhost:3000/', {
method: 'POST',
headers: {
'Accept': 'application/json',
//'Content-Type': 'application/json',
},
body: JSON.stringify({chat: encodeURIComponent(m.getInnerHTML())})
})
.then(response => response.json())
.then(response => process_bot(response))
}
observeDOM(() => process_chat(), document.querySelector("#" + parent_id));
//---localhost
//flasktester.py
// flask --app flasktester run --port 3000
import datetime
from flask import Flask, request, jsonify
import json
from urllib.parse import unquote
app = Flask(__name__)
counter = 0
@app.post("/")
def hello_world():
global counter
messages = json.loads(str(request.get_data().decode('utf-8')))
print ('hi ' + str(counter))
counter = counter + 1
#print(request["body)
#print(request.content_length)
#print(request.content_type)
#print(request.get_data())
#print(request.get_json())
if (messages is not None):
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
#filename = f"messages_{timestamp}.txt"
#with open(filename, 'w') as file:
#file.write(unquote(messages["chat"].replace('"', '')))
response = jsonify({'some': counter})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment