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{
//window.location.href = window.location.protocol + '//' + window.location.host;
alert("Wallet isn't connected.");
}
}
document.body.addEventListener("click", function(e) {
if(e.target && e.target.nodeName == "A") {
var url = e.target.getAttribute('href');
if(url.split(':', 2)[0] === "tela"){
sendData({"jsonrpc": "2.0","id": "1","method": "HandleTELALinks","params":{"telaLink": url}});
}else if(url) {
e.preventDefault();
window.history.pushState({},"", url);
loadPage();
}
}
});
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(){
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>";
}
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){
if(resource.resType === "tela"){
let json = {};
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'] |