Add clientside dom parsers

This commit is contained in:
Nicholas Jitkoff 2022-05-11 22:35:27 -07:00
parent 0afa3d64dc
commit 97a7c4daac
2 changed files with 10 additions and 0 deletions

View file

@ -27,6 +27,7 @@
const renderers = {
"application/ld+json": {script:"recipe"},
"text/rawhtml": {script:"parse"},
"javascript": {script:"bookmarklet"},
"web3": {script:"web3", mode:"frame"},
}

9
docs/render/parse.js Normal file
View file

@ -0,0 +1,9 @@
// let title = params.title
const parser = new DOMParser();
const doc = parser.parseFromString(params.body, "text/html");
let ldjson = doc.querySelector('script[type="application/ld+json"]').innerText.trim();
let f = new FileReader();
f.onload = function(e) { top.location.href = ( '/#/' + e.target.result);};
f.readAsDataURL(new Blob([ldjson],{type : 'application/ld+json;charset=utf-8'}));