From 22bdc082a3fb26144f861732a971e091718a215f Mon Sep 17 00:00:00 2001 From: kaotisk Date: Mon, 11 Nov 2024 23:37:28 +0200 Subject: Refactoring using ak-generator --- src/js/arching-kaos-modules-mixtapes.js | 91 ++++++++++++++++----------------- 1 file changed, 45 insertions(+), 46 deletions(-) (limited to 'src/js/arching-kaos-modules-mixtapes.js') diff --git a/src/js/arching-kaos-modules-mixtapes.js b/src/js/arching-kaos-modules-mixtapes.js index 2702e95..ac23ed4 100644 --- a/src/js/arching-kaos-modules-mixtapes.js +++ b/src/js/arching-kaos-modules-mixtapes.js @@ -9,51 +9,52 @@ function akModuleMixtapes(zblockIPFSHash, zblockObject, blockObject, json){ if(!document.querySelector('#mixtape-'+zblockIPFSHash)){ var divs = document.querySelector('#mixtapes-section'); - var art = document.createElement("article"); - art.id = 'mixtape-'+zblockIPFSHash; - if(json.title){ - var h3 = document.createElement("h3"); - h3.innerText = json.title; - art.appendChild(h3); - } - if(json.artist){ - var h4 = document.createElement("h4"); - h4.innerText = json.artist; - art.appendChild(h4); - } - if(json.timestamp){ - var small = document.createElement("h5"); - small.innerText="Published: " + new Date(json.timestamp*1000); - art.appendChild(small); - } - if(json.ipfs){ - var audio = document.createElement("audio"); - audio.setAttribute('controls',''); - audio.id = 'mixtape-player-'+zblockIPFSHash; - mixtapeIds.push(audio.id); - var source = document.createElement("source"); - source.src = getIPFSURL(json.ipfs); - var rs = source.cloneNode(true); - audio.appendChild(source); - //radio.appendChild(rs); - art.appendChild(audio); - audio.addEventListener( "loadedmetadata", ()=>{ - if ( mixtapes[zblockIPFSHash] === undefined ){ - mixtapes[zblockIPFSHash]={ - zblock:zblockIPFSHash, - block:zblockObject.block, - block_signature:zblockObject.block_signature, - action:blockObject.action, - previous:blockObject.previous, - data:blockObject.data, - dataExpansion:json, - detach:blockObject.detach, - gpg:blockObject.gpg, - timestamp:blockObject.timestamp, - audioDuration:audio.duration - }; + var art = { + element:"article", + id:'mixtape-'+zblockIPFSHash, + innerHTML:[ + { + element:"h3", + innerText:(json.title)?json.title:'' + }, + { + element:"h4", + innerText:(json.artist)?json.artist:'' + }, + { + element:"h5", + innerText:"Published: " + (json.timestamp)?new Date(json.timestamp*1000):'' + }, + { + element:"audio", + id:'mixtape-player-'+zblockIPFSHash, + innerHTML:[ + { element:"source", src: getIPFSURL(json.ipfs)} + ] } - /* console.log( + ] + }; + makeElement(art, divs); + var audio = document.querySelector('#mixtape-player-'+zblockIPFSHash); + audio.setAttribute('controls',''); + mixtapeIds.push('mixtape-player-'+zblockIPFSHash); + audio.addEventListener( "loadedmetadata", ()=>{ + if ( mixtapes[zblockIPFSHash] === undefined ){ + mixtapes[zblockIPFSHash]={ + zblock:zblockIPFSHash, + block:zblockObject.block, + block_signature:zblockObject.block_signature, + action:blockObject.action, + previous:blockObject.previous, + data:blockObject.data, + dataExpansion:json, + detach:blockObject.detach, + gpg:blockObject.gpg, + timestamp:blockObject.timestamp, + audioDuration:audio.duration + }; + } + /* console.log( zblockIPFSHash+"'s duration is: "+ audio.duration + " Ceiled: " + Math.ceil(audio.duration) + @@ -62,9 +63,7 @@ function akModuleMixtapes(zblockIPFSHash, zblockObject, blockObject, json){ " DIFF: " + (blockObject.timestamp - json.timestamp) ); */ }, false ); - } if (document.querySelector("#mixtapes-sec-not-found")) document.querySelector("#mixtapes-sec-not-found").hidden=true; - divs.appendChild(art); } } // @license-end -- cgit v1.2.3