Tidals Worker Runtime
const tasks = await require("env/tasks");
tasks.trigger("sealable:gen_secret", ["note-info", "Huh?", "Press \"Edit\" to see the source!"]);
You can run limited JavaScript using the custom module loader in a separate thread using a code block with "worker" set as the language.
To call functions from the main thread (outside the worker), you can use require their namespace and then call their functions directly. You can view all namespaces and their usages here.
const { prompt } = await require("env/window");
const tasks = await require("env/tasks");
const name = await prompt("Your name:");
tasks.trigger("sealable:gen_secret", ["note-info", "Name", name]);
Complex data is not able to be passed into the worker script, meaning this won't work:
const element = document.getElementById("test");
console.log(element);
You can also skip all the random extra syntax and use the $
function directly:
const name = await $(["prompt", "Your name:"]);
$(["trigger", "sealable:gen_secret", ["note-info", "Name", name]]);
The syntax in the first example is just a wrapper around the first that registers imported namespaces with the correct methods.
Namespaces
Window env/window
alert
- https://developer.mozilla.org/en-US/docs/Web/API/Window/alertprompt
- https://developer.mozilla.org/en-US/docs/Web/API/Window/promptconfirm
- https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm
Tasks env/tasks
spawn
- spawn a new worker with the givencode
trigger
- trigger a global namespace function
Color env/color
You can read the color of something by CSS selector with:
const { alert } = await require("env/window");
const { read_color } = await require("env/color");
alert(await read_color("body"));
read_color
returns: [background color, text color]
You can globally replace a color on the page with:
const { swap_color } = await require("env/color");
// light mode background
swap_color("rgb(212, 212, 212)", "#000000");
// dark mode background
swap_color("#171717", "#ffffff");
DOM env/dom
An example of DOM manipulation is shown below:
const dom = await require("env/dom");
// create element
const element_id = await dom.create_element("button", "main");
// set content
await dom.update_element_property(element_id, "innerText", "New Button");
// set class
await dom.update_element_attribute(element_id, "class", "round");