added iframe detection

This commit is contained in:
PossiblyAxolotl 2024-08-17 21:45:35 -06:00
parent 81acb17fc0
commit 66840460b6
3 changed files with 62 additions and 3 deletions

29
apps/piracy.html Normal file
View file

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
<link rel="stylesheet" href="standard.css">
<style>
* {
text-align: center;
}
</style>
</head>
<body>
<script>
function createWindow(url, name, w, h) {
window.parent.postMessage(`win ${url} ${name} ${w} ${h}`)
}
</script>
<h1>Woah there!</h1>
<p>If you're seeing this that means you're playing this on the wrong website!</p>
<p>Don't worry though, simply click that button and I'll take you to where you can play this game.</p>
<button onclick="window.top.location.href = 'https://i-eat.rocks'"><span class="rainbow">Take me there!</span></button>
</body>
</html>

View file

@ -48,11 +48,41 @@
<nav></nav> <nav></nav>
<script defer> <script defer>
function getTopLevelUrl() {
try {
return window.top.location.href;
} catch (e) {
return window.location.href;
}
}
function inList(list, val) {
for (var i = 0; i < list.length; i++) {
if (list[i] === val) {
return true;
}
}
return false
}
addEventListener("DOMContentLoaded", e => { addEventListener("DOMContentLoaded", e => {
var topLevelUrl = getTopLevelUrl().split("/")[2];
const allowedURLs = ["i-eat.rocks", "possiblyaxolotl.itch.io", "127.00.1:5500"];
if (inList(allowedURLs, topLevelUrl) == false) {
const divs = document.querySelectorAll("div");
divs.forEach(div => {
div.remove();
});
createWindow('apps/piracy.html', 'wuh oh!', '350px', '330px');
} else {
createWindow('apps/welcome.html', 'welcome', '350px', '550px'); createWindow('apps/welcome.html', 'welcome', '350px', '550px');
}
}) })
window.home = window.self;
</script> </script>
</body> </body>
</html> </html>

View file

@ -166,5 +166,5 @@ nav {
box-shadow: 0px 0px 4px rgba(0,0,0,0.5); box-shadow: 0px 0px 4px rgba(0,0,0,0.5);
z-index: 2147483647; /*z-index: 2147483647;*/
} }