Skip to content

Instantly share code, notes, and snippets.

@flarn2006
Last active March 1, 2022 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flarn2006/fe0b0c30219b492ea1d787ceda6b9b2b to your computer and use it in GitHub Desktop.
Save flarn2006/fe0b0c30219b492ea1d787ceda6b9b2b to your computer and use it in GitHub Desktop.
Things Recipe Logger
import flask
from flask_cors import CORS
flask_app = flask.Flask(__name__)
CORS(flask_app)
with open('recipes.txt', 'a') as f:
@flask_app.route('/recipe', methods=['POST'])
def flask_recipe():
text = flask.request.data.decode('utf-8')
if 'discover' in text:
print(text, file=f)
f.flush()
return 'ok'
flask_app.run(port=8765)
// ==UserScript==
// @name Things Recipe Logger
// @version 1.1
// @match https://lab.latitude.io/main/things/things-play-level*
// @grant none
// ==/UserScript==
const console_prefix = '[Recipe Logger]';
var toast = null;
var toast_text;
function callback(mutationsList, observer)
{
if (toast.innerText != toast_text) {
toast_text = toast.innerText;
console.log(console_prefix, toast_text);
const xhr = new XMLHttpRequest();
xhr.open('POST', 'http://127.0.0.1:8765/recipe');
xhr.send(toast_text);
}
}
window.addEventListener('load', function() {
setInterval(function() {
const current_toast = document.querySelector('.things-result-toast');
if (current_toast && current_toast !== toast) {
toast = current_toast;
console.log(console_prefix, 'Found result toast.');
toast.style.textTransform = 'none';
toast_text = toast.innerText
const observer = new MutationObserver(callback);
observer.observe(toast, {subtree:true, childList:true, characterData:true});
}
}, 100);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment