|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Bloxcraft UBG - Games</title> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 | + <link id="favicon" rel="shortcut icon" type="image/png" href="/bloxcraft.png"> |
| 8 | + <link rel="stylesheet" href="/app-viewer/app-viewer-default.css"> |
| 9 | + |
| 10 | + <script async src="https://www.googletagmanager.com/gtag/js?id=G-W0KXN0103E"></script> |
| 11 | + <script> |
| 12 | + window.dataLayer = window.dataLayer || []; |
| 13 | + function gtag(){dataLayer.push(arguments);} |
| 14 | + gtag('js', new Date()); |
| 15 | + gtag('config', 'G-W0KXN0103E'); |
| 16 | + </script> |
| 17 | + |
| 18 | + <script> |
| 19 | + (function(w,d,s,l,i){ |
| 20 | + w[l]=w[l]||[]; |
| 21 | + w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'}); |
| 22 | + var f=d.getElementsByTagName(s)[0], |
| 23 | + j=d.createElement(s), |
| 24 | + dl=l!='dataLayer'?'&l='+l:''; |
| 25 | + j.async=true; |
| 26 | + j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl; |
| 27 | + f.parentNode.insertBefore(j,f); |
| 28 | + })(window,document,'script','dataLayer','GTM-NQM8XR48'); |
| 29 | + </script> |
| 30 | +</head> |
| 31 | + |
| 32 | +<body> |
| 33 | +<div id="viewerBar"> |
| 34 | + <p id="viewerTitle">Loading...</p> |
| 35 | + <div id="Btn-Group"> |
| 36 | + <a class="bloxy-blue-btn bloxy-btn" href="/games">Close</a> |
| 37 | + <a class="bloxy-blue-btn bloxy-btn" id="closeViewer">Google</a> |
| 38 | + <a class="bloxy-blue-btn bloxy-btn" id="openNewTab">Play In New Tab</a> |
| 39 | + </div> |
| 40 | +</div> |
| 41 | + |
| 42 | +<iframe id="viewerFrame"></iframe> |
| 43 | + |
| 44 | +<script> |
| 45 | +const params = new URLSearchParams(window.location.search); |
| 46 | +const id = params.get("view"); |
| 47 | + |
| 48 | +const JSON_URL = "https://cdn.jsdelivr.net/gh/tharun9772/game-assets@main/ccported-stupid-game-lib.json"; |
| 49 | + |
| 50 | +const viewerFrame = document.getElementById("viewerFrame"); |
| 51 | +const viewerTitle = document.getElementById("viewerTitle"); |
| 52 | +const openNewTab = document.getElementById("openNewTab"); |
| 53 | + |
| 54 | +function show404(){ |
| 55 | + viewerFrame.srcdoc = ` |
| 56 | + <style> |
| 57 | + body{ |
| 58 | + background:black; |
| 59 | + color:white; |
| 60 | + display:flex; |
| 61 | + justify-content:center; |
| 62 | + align-items:center; |
| 63 | + height:100vh; |
| 64 | + font-family:sans-serif; |
| 65 | + } |
| 66 | + </style> |
| 67 | + 404 Not Found |
| 68 | + `; |
| 69 | + viewerTitle.textContent = ""; |
| 70 | +} |
| 71 | + |
| 72 | +if(!id){ |
| 73 | + show404(); |
| 74 | +} else { |
| 75 | + |
| 76 | + fetch(JSON_URL) |
| 77 | + .then(r => r.json()) |
| 78 | + .then(data => { |
| 79 | + |
| 80 | + const game = data.find(g => String(g.Id) === id); |
| 81 | + if(!game || !game.base) throw new Error(); |
| 82 | + |
| 83 | + const fullUrl = game.base + "/index.html"; |
| 84 | + |
| 85 | + viewerTitle.textContent = game.name && game.name.trim() |
| 86 | + ? game.name |
| 87 | + : "Game " + game.Id; |
| 88 | + |
| 89 | + fetch(fullUrl) |
| 90 | + .then(r => { |
| 91 | + if(!r.ok) throw new Error(); |
| 92 | + return r.text(); |
| 93 | + }) |
| 94 | + .then(html => { |
| 95 | + viewerFrame.srcdoc = html; |
| 96 | + }) |
| 97 | + .catch(show404); |
| 98 | + |
| 99 | + openNewTab.onclick = async () => { |
| 100 | + try{ |
| 101 | + const html = await fetch(fullUrl).then(r => r.text()); |
| 102 | + const tab = window.open("about:blank", "_blank"); |
| 103 | + |
| 104 | + if(!tab){ |
| 105 | + alert("Popup blocked"); |
| 106 | + return; |
| 107 | + } |
| 108 | + |
| 109 | + tab.document.open(); |
| 110 | + tab.document.write(html); |
| 111 | + tab.document.close(); |
| 112 | + |
| 113 | + }catch{ |
| 114 | + alert("Failed to open game"); |
| 115 | + } |
| 116 | + }; |
| 117 | + |
| 118 | + }) |
| 119 | + .catch(show404); |
| 120 | +} |
| 121 | + |
| 122 | +document.getElementById("closeViewer").onclick = ()=>{ |
| 123 | + window.top.location.href = "https://google.com/"; |
| 124 | +}; |
| 125 | +</script> |
| 126 | +</body> |
| 127 | +</html> |
0 commit comments