function graph(fn) {
  let result=document.createElement("canvas");
  let ctx=result.getContext("2d");
  ctx.beginPath();
  for (let tx=0; tx<result.width; tx++) {
    let x=tx/result.width;
    ctx.lineTo(tx,fn(x)*result.height);    
  }
  ctx.stroke();
  return result;
}

// only works with HTTPS I believe
function embed(url){
const urlData = new URL(url);
let result = document.createElement("div");
async function process() {
const providers = await fetch("./providers.json")
    .then(res => res.json());
const check = urlData.protocol + "//" + urlData.host;
let schema = null
let providerPointer = 0
while (schema === null) {
let current = providers[providerPointer]
if (current.provider_url == check) {
schema = current.endpoints.url
}
providerPointer++
}
result.innerHTML = await fetch(schema + "/" + url)
    .then(res => res.json())
    .then(res => res.html)
}
process()
return result
}
  
//Crazazy's variation on kahole and Lerc's scratch page
"Press Ctrl+Enter to evaluate current line or selection"

3 * 33 + 7
"<b>Result is added as HTML! (execute this line)</b>"
"<iframe width='700' height='400' src='https://crazazy.github.io/nixos-config'></iframe>"
Math.random() > 0.3 ? "<style>body {background-color: #fdf6e3;}</style>" : "try again!";
graph(a=>Math.sin(a*20)/2+0.5);
// The document state is stored in localStorage on page-unload.

// Built-in functions
reset() // - reset the doc to this tutorial
clear() // - empty the doc
save() // - save doc state to localStorage

// Feel free to save the source of this page and use it locally, it'll work the same.
window.open("https://gist.github.com/kahole/651990b888c19b84d5700422daa961de", "_blank")

// Inspirational works
[ "Emacs scratch buffer", window.open("https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Interaction.html", "_blank") ]
[ "Secretgeek's html quine", window.open("https://secretgeek.github.io/html_wysiwyg/html.html", "_blank") ]