diff options
author | alyx <alyx@aleteoryx.me> | 2022-02-06 16:09:29 +0000 |
---|---|---|
committer | Aleteoryx <alyx@aleteoryx.me> | 2022-02-06 16:09:29 +0000 |
commit | fb1876db725b1d96d3fb58d2a597a12e36ca7b39 (patch) | |
tree | e3fe932f2ba848dbb6b3f2f13816aead257a4d6a /grapher/pl/script.js | |
parent | 21bc06407c450a3ae5643d5462c452ec92b3d782 (diff) | |
download | RRCUtils-fb1876db725b1d96d3fb58d2a597a12e36ca7b39.tar.gz RRCUtils-fb1876db725b1d96d3fb58d2a597a12e36ca7b39.tar.bz2 RRCUtils-fb1876db725b1d96d3fb58d2a597a12e36ca7b39.zip |
permalinking is fully operational
Diffstat (limited to 'grapher/pl/script.js')
-rw-r--r-- | grapher/pl/script.js | 40 |
1 files changed, 40 insertions, 0 deletions
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 |