<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Thirdshelf Dev Simulator</title>
<style>
pre { display: inline-block; }
</style>
</head>
<body>
<strong>Thirdshelf Simulator</strong>
<pre>received query params:</pre>
<pre id="debug"></pre>
<button onClick="sendShow()">Send Show</button>
<button onClick="sendHide()">Send Hide</button>
<button onClick="sendRedirect()">Send Redirect</button>
<script>
function urlParams() {
var urlParams = {};
var match,
pl = /\+/g,
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
return urlParams
}
function sendMessage(message) {
parent.postMessage(JSON.stringify(message), '*');
}
function sendShow() {
sendMessage({ command: 'show' })
}
function sendHide() {
sendMessage({ command: 'hide' })
}
function sendRedirect() {
sendMessage({
command: 'redirect',
params: {
url: 'https://thirdshelf.com',
},
})
}
document.getElementById('debug').textContent = JSON.stringify(urlParams())
setTimeout(function() {
parent.sagamore.showThirdshelf();
}, 2000)
</script>
</body>
</html>