From fb1876db725b1d96d3fb58d2a597a12e36ca7b39 Mon Sep 17 00:00:00 2001 From: alyx Date: Sun, 6 Feb 2022 16:09:29 +0000 Subject: permalinking is fully operational --- grapher/pl/script.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 grapher/pl/script.js (limited to 'grapher/pl/script.js') diff --git a/grapher/pl/script.js b/grapher/pl/script.js new file mode 100644 index 0000000..c47a636 --- /dev/null +++ b/grapher/pl/script.js @@ -0,0 +1,40 @@ +window.addEventListener('load', async e => { + const frame = document.getElementById('frame'); + const author = document.getElementById('author'); + const linker = document.getElementById('linker'); + + linker.target = window.location.hash.substr(1); + + const graph = await (await fetch(`https://graphpl.aleteoryx.me/load/${window.location.hash.substr(1)}`)).json() + if (frame.contentWindow.document.readyState != 'complete') + await new Promise((res, rej) => frame.contentWindow.addEventListener('load', e => {res();})); + + author.innerText = graph.author ? graph.author : [ + "a ghost", + "nobody", + "thine mother", + "god's mistake", + "the zodiac killer", + "tyleo, secretly", + "someone else", + "Danny Elfman", + "a rat in a cage", + "viewers like you" + ][Math.round(Math.random() * 10)]; + + frame.contentWindow.postMessage({type: 'lock'}); + frame.contentWindow.postMessage({type: 'loadGraph', graph: graph}); + + linker.addEventListener('click', e => { + let newwin = window.open('', window.location.hash.substr(1)); + window.onmessage = ({data}) => { + console.log(data.type); + if(data.type == 'grapherLoaded') { + newwin.postMessage({type: 'loadGraph', graph: graph}); + newwin.name = ''; + window.onmessage = null; + } + } + }) + +}) \ No newline at end of file -- cgit v1.2.3-54-g00ecf