SC Arguments: [Name:SC_ACTION Type:uint64 Value:'0' Name:SC_ID Type:hash Value:'970659c33de7db38a7928ae5024fd1a5da1401ea8f037cbf3ad5ab8f83215786' Name:content Type:string Value:'//This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
window.addEventListener("popstate", loadPage);
function loadPage(){
if (socket && socket.readyState === WebSocket.OPEN) {
setResources();
}else{
alert("Wallet isn't connected.");
}
}
document.body.addEventListener("click", function(e) {
let target = e.target
let isALink = false;
while (target && target !== document) {
if (target.nodeName == 'A') {
isALink = true;
break;
}
target = target.parentElement;
}
if(e.target && isALink){
let url = e.target.getAttribute('href');
let hname = getHost(url);
if(url.split(':', 2)[0] === "tela"){
sendData({"jsonrpc": "2.0","id": "1","method": "HandleTELALinks","params":{"telaLink": url}});
}else if(hname != 'localhost' && hname != null){
let result = confirm("You are leaving Tela and visiting a www site. OK?");
if (!result) {
e.preventDefault();
}
}else if(url) {
e.preventDefault();
window.history.pushState({},"", url);
loadPage();
}
}
});
function getHost(url) {
try {
let urlO = new URL(url);
return urlO.host;
} catch (e) {
return null;
}
}
function getResourceList(){
let location = document.location.href.split('#!', 2)[1];
location = typeof location === 'undefined' ? 'home' : location;
return resourceList[location];
}
var resources;
var socket_response = 0;
function setResources(){
if (!document.querySelector('#global')){
const style = document.createElement('style');
style.id = 'global';
style.innerHTML = "body{background-color:#000;}";
document.head.appendChild(style);
}
document.querySelectorAll(".page").forEach(el => el.remove());
document.body.innerHTML = "";
resources = getResourceList();
if(typeof resources ==='undefined'){
document.body.innerHTML = "<h1>Not Found</h1><a href='/'>Home</a>";
socket_response = 0;
socket.removeEventListener("message", socketListener);
return
}
function socketListener(event) {
function hexToUtf8(s){
return decodeURIComponent(s.replace(/\s+/g, '').replace(/[0-9a-f]{2}/g, '%$&'));
}
console.log("Content message Recieved");
let lastObj = JSON.parse(event.data);
if(typeof lastObj.result === 'undefined' ){
alert("Error Retrieving Content");
return;
}
let res = lastObj.result;
if(socket_response < resources.length ){
let resource = resources[socket_response++];
let resource_content = "";
if(typeof res.code !== 'undefined' && res.code.includes('STORE("docType", "TELA')){
let html = res.code.split('/*', 2)[1];
resource_content = html.split('*/', 2)[0];
}else if(hexToUtf8(res.stringkeys["scType"]) === "TELA-ASSET"){
resource_content = hexToUtf8(res.stringkeys[resource.name]);
}
if(resource.type == 'html'){
document.body.innerHTML = document.body.innerHTML + resource_content;
}else if(resource.type == 'style' || resource.type == 'script'){
let ele = document.createElement(resource.type);
ele.textContent = resource_content;
ele.classList.add("page");
document.head.appendChild(ele);
}
if(socket_response < resources.length ){
getContent(resources[socket_response]);
}else{
socket_response = 0;
socket.removeEventListener("message", socketListener);
}
}
}
socket.addEventListener("message", socketListener);
//Start loading
getContent(resources[0]);
function getContent(resource){
let json = {};
if(resource.resType === "tela"){
json.jsonrpc = "2.0";
json.id = "1";
json.method = "DERO.GetSC";
json.params = {};
json.params.scid = resource.scid;
json.params.code = true;
json.params.variables = true;
sendData(json);
}else if(resource.resType === "sc"){
json.jsonrpc = "2.0";
json.id = "1";
json.method = "DERO.GetSC";
json.params = {};
json.params.scid = resource.scid;
json.params.code = false;
json.params.variables = true;
sendData(json);
}
}
}
var resourceList = [];
' Name:entrypoint Type:string Value:'StoreItem' Name:name Type:string Value:'initscript'] |