Last active
March 1, 2022 19:59
-
-
Save flarn2006/fe0b0c30219b492ea1d787ceda6b9b2b to your computer and use it in GitHub Desktop.
Things Recipe Logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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