better information catching from Astroport

This commit is contained in:
fred 2023-12-30 18:38:43 +01:00
parent e8f8ff5f8d
commit 2a7323f67e
6 changed files with 285 additions and 9 deletions

90
earth/astro.js Normal file
View File

@ -0,0 +1,90 @@
<!-- homeAstroportStation function API Twist -->
// Include <div id="ainfo"></div> in your HTML
async function ainfo(zURL){
try {
let two = await fetch(zURL); // Gets a promise
var miam = await two.text();
console.log(miam)
document.getElementById("ainfo").innerHTML = two.text(); // Replaces id='ainfo' with response
} catch (err) {
console.log('Fetch error:' + err); // Error handling
}
}
// Include <div id="countdown"></div> in your HTML
async function homeAstroportStation(myURL, option = '', duration = 3000) {
try {
let one = await fetch(myURL); // Gets a promise
var doc = await one.text();
var regex = /url='([^']+)/i; // Get response PORT
var redirectURL = doc.match(regex)[1]
console.log(option + " ... Teleportation ... in " + duration + " ms ... " + redirectURL)
// start countdown
var timeLeft = Math.floor(duration / 1000);
var elem = document.getElementById("countdown");
var timerId = setInterval(countdown, 1000);
function countdown() {
if (timeLeft == -1) {
clearTimeout(timerId);
switch(option) {
case "tab":
window.open( redirectURL, "AstroTab");
break;
case "page":
window.location.replace(redirectURL);
break;
case "parent":
window.parent.location.href = redirectURL;
break;
case "aframe":
document.getElementById("aframe").src = redirectURL;
break;
case "ainfo":
ainfo(redirectURL);
break;
default:
window.location.href = redirectURL;
}
if (document.getElementById("countdown").innerHTML !== '') {
document.getElementById("countdown").innerHTML = "<a href='"+redirectURL+"' target='aframe'>OK</a>";
}
} else {
elem.innerHTML = timeLeft + " s";
timeLeft--;
}
}
} catch (err) {
console.log('Fetch error:' + err + myURL ); // Error handling
}
}
// <center><div id="countdown"></div></center>
function promptUser(inout) {
let salt = prompt("Secret 1");
let pepper = prompt("Secret 2");
let email = prompt("Email");
let resultUt = '/?salt=' + salt + '&pepper=' + pepper + '&' + inout + '=' + email;
console.log(resultUt)
homeAstroportStation( resultUt,'', 12000)
}

View File

@ -20,7 +20,26 @@
<script type="text/javascript" src="demo.js"></script>
<script src="astro.js"></script>
<script type="text/javascript">
// Extract the hostname (e.g., "https://ipfs.domain.tld" or "http://ipfs.localhost:8080")
var currentURL = new URL(window.location.href);
var hostname = currentURL.hostname;
var port = currentURL.port;
var protocol = currentURL.protocol.split(":")[0];
// Check and replace the port if it's 8080
if (port === "8080") {
port = "1234";
}
var zHost = hostname.replace("ipfs", "astroport");
// Create the "station" variable with the specified format
var station = protocol + "://" + zHost + (port ? (":" + port) : "");
console.log(station)
examples['simple_mars'] = function() {
$('#sphere').earth3d({
texture: 'maps/sector0_miz.jpg', // texture used on sphere
@ -117,7 +136,8 @@
<body>
<h1>♥ U Planet ♥</h1>
<a href="scan/">SCAN</a>
<button onclick="homeAstroportStation(station+'/?qrcode=station', '', 21654)">Ẑen Station</button>
<div id="countdown"></div>
<br><a href="login/">LOGIN</a>
<div id="container">

View File

@ -94,33 +94,44 @@
var station = protocol + "://" + zHost + (port ? (":" + port) : "");
console.log(station)
//////////////////////////////////////////////////////////////// fetchAstroport
async function fetchAstroport(myURL) {
async function fetchAstroport(myURL, retryCount = 3) {
try {
let one = await fetch(myURL); // Gets a promise
let one = await fetch(myURL);
var doc = await one.text();
var regex = /url='([^']+)/i; // Get response PORT
var regex = /url='([^']+)/i;
var redirectURL = doc.match(regex)[1];
console.log(redirectURL);
return new Promise((resolve, reject) => {
setTimeout(async function () {
return new Promise(async (resolve, reject) => {
let retry = 0;
const fetchData = async () => {
try {
let two = await fetch(redirectURL);
const data = await two.json();
console.log(data);
resolve(data);
} catch (error) {
console.log('Fetch error (inside setTimeout):', error);
if (retry < retryCount) {
console.log(`Retry ${retry + 1} after 3000ms...`);
retry++;
setTimeout(fetchData, 3000);
} else {
console.log('Max retries reached. Fetch error:', error);
reject(error);
}
}, 3000);
}
};
setTimeout(fetchData, 3000);
});
} catch (err) {
console.log('Fetch error:', err);
return Promise.reject(err);
}
}
///////////////////////////////////////////////////////////////////////////////////

BIN
earth/maps/sector0_miz.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 KiB

70
earth/scan/pinMeBB.css Normal file
View File

@ -0,0 +1,70 @@
#pinpad form {
width: 390px;
margin: 50px auto;
background: #fff;
padding: 35px 25px;
text-align: center;
box-shadow: 0px 5px 5px -0px rgba(0, 0, 0, 0.3);
border-radius: 5px;
}
#displayPass {
padding: 0 40px;
border-radius: 5px;
width: 350px;
margin: auto;
border: 1px solid rgb(228, 220, 220);
outline: none;
font-size: 60px;
color: transparent;
text-shadow: 0 0 0 rgb(71, 71, 71);
text-align: center;
}
input:focus {
outline: none;
}
.pinButton {
border: none;
background: none;
font-size: 1.5em;
border-radius: 50%;
height: 60px;
font-weight: 550;
width: 60px;
color: transparent;
text-shadow: 0 0 0 rgb(102, 101, 101);
margin: 7px 20px;
}
.clear,
.enter {
font-size: 1em !important;
}
.pinButton:hover {
box-shadow: #506ce8 0 0 1px 1px;
}
.pinButton:active {
background: #506ce8;
color: #fff;
}
.clear:hover {
box-shadow: #ff3c41 0 0 1px 1px;
}
.clear:active {
background: #ff3c41;
color: #fff;
}
.enter:hover {
box-shadow: #47cf73 0 0 1px 1px;
}
.enter:active {
background: #47cf73;
color: #fff;
}

85
earth/scan/pinMeBB.js Normal file
View File

@ -0,0 +1,85 @@
function pinMeBB(
elID,
data = {
limit: 5,
minChar: 5,
show: 0,
}
) {
if ((data.minChar || data.limit) > data.limit) data.limit = data.minChar;
var el = document.getElementById(elID);
el.insertAdjacentHTML(
"beforeend",
`
<form autocomplete="off">
<input id='displayPass' readonly type="text" autocomplete="off" maxlength="${data.limit}"/></br>
<input type='hidden' id="password" maxlength="${data.limit}"/>
<input type="button" value="1" id="1" class="pinButton calc"/>
<input type="button" value="2" id="2" class="pinButton calc"/>
<input type="button" value="3" id="3" class="pinButton calc"/><br>
<input type="button" value="4" id="4" class="pinButton calc"/>
<input type="button" value="5" id="5" class="pinButton calc"/>
<input type="button" value="6" id="6" class="pinButton calc"/><br>
<input type="button" value="7" id="7" class="pinButton calc"/>
<input type="button" value="8" id="8" class="pinButton calc"/>
<input type="button" value="9" id="9" class="pinButton calc"/><br>
<input type="button" value="clear" id="clear" class="pinButton clear"/>
<input type="button" value="0" id="0 " class="pinButton calc"/>
<input type="button" value="enter" id="enter" class="pinButton enter"/>
</form>
`
);
const input_value = document.getElementById("password");
const display_value = document.getElementById("displayPass");
const eventEnter = new CustomEvent("onEnter", {
bubbles: true,
detail: { password: () => input_value.value },
});
const eventMaxed = new CustomEvent("onMaxChar",{
detail: { password: () => input_value.value },
});
const eventEmpty = new CustomEvent("onEmpty",{
detail: { password: () => input_value.value },
});
function field(value) {
if (input_value.value.length >= data.limit) {
el.dispatchEvent(eventMaxed);
} else {
input_value.value = input_value.value + value;
// TODO if show == 1 display_value.value = display_value.value + value;
display_value.value += data.show === 1 ? value : "*";
}
}
document
.getElementById("enter")
.addEventListener("click", (e) =>
el.dispatchEvent(
input_value.value.length < (data.minChar || data.limit)
? eventEmpty
: eventEnter
)
);
document.getElementById("clear").addEventListener("click", (e) => {
input_value.value = "";
display_value.value = "";
});
var pads = document.getElementsByClassName("calc");
for (var i = 0; i < pads.length; i++) {
pads[i].addEventListener("click", (e) => {
field(e.target.value);
});
pads[i].addEventListener("keydown", (e) => {
if (e.keyCode === 13) {
e.preventDefault();
}
});
}
return el;
}