Mercurial > code > home > repos > front-door-display
diff src/scheduleLcd.ts @ 4:e273cc60b389
draft of web-to-lcd and simulator
author | drewp@bigasterisk.com |
---|---|
date | Tue, 05 Mar 2024 18:12:15 -0800 |
parents | 1cfca88f76d0 |
children | d97a5930db7e |
line wrap: on
line diff
--- a/src/scheduleLcd.ts Tue Mar 05 17:24:18 2024 -0800 +++ b/src/scheduleLcd.ts Tue Mar 05 18:12:15 2024 -0800 @@ -10,6 +10,44 @@ const EV = "http://bigasterisk.com/event#"; const RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; + +// Function to send a POST request +function sendPostRequest(data) { + fetch('https://example.com/api', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + console.log('POST request successful'); + // Handle response data if needed + }) + .catch(error => { + console.error('There was a problem with the POST request:', error); + }); +} + +// Callback function to handle DOM changes +function handleDomChanges(mutationsList, observer) { + // Send a POST request whenever the DOM changes + sendPostRequest({ domChanges: mutationsList }); +} + +// Create a MutationObserver instance +const observer = new MutationObserver(handleDomChanges); + +// Start observing the DOM for changes +observer.observe(document.body, { subtree: true, childList: true, attributes: true }); + + function getLiteral(store: Store, graph: Term, subj: Quad_Subject, pred: Quad_Predicate, missing: string | null): string { let out = null; store.getObjects(subj, pred, graph).forEach((attr) => {