'use strict'; // Copyright (C) 2026 ListIt.guru All Rights Reserved. // ListIt.guru Class JSON to HTML list/gallery output // ListIt View V4 // ver 4 BETA class buildDisplay { constructor(options = {}) { this.data = options.data; this.view = options.view; this.itemsheight = []; this.rowon = 1; this.totalrowwidth = 0; this.easyload = false; this.maxwidth = 200; this.listid = options.listid; this.processdata = options.processdata; this.view2 = options.view2; this.sort = options.sort === undefined ? 'date' : options.sort; this.startat = 0; this.endat = options.endat === undefined ? 43 : options.endat; this.filldiv = options.filldiv; this.preview = options.preview === undefined ? false : options.preview ; this.append = false; this.showItem = options.showItem; this.searchParams = new URLSearchParams(window.location.search); this.title = options.title; this.hits = options.hits; this.helper = (options.helper !== undefined) ? options.helper : false; this.dsize = this.data.length; if(this.sort == 'views'){ let allhitsxx = 0; for(var i = 0;iMessage'}); return; } let commentbox = jpmplayer.getElem('imgcomment-'+id); let comment = commentbox.value; commentbox.disabled = true; commentbox.value = 'Saving comment...'; comment = jpmplayer.convertHtmlToText(comment); const x = new Date(); const stamp = Math.floor(Date.now() / 1000);//(x.getTime() + x.getTimezoneOffset()*60*1000)/1000; console.log(comment.split('\n').length); if(comment.split('\n').length > 8){ popFillNew.notify({'msg':'Too many line breaks.','overwrite':true}); commentbox.value = ''; commentbox.disabled = false; }else if(comment.length > 300){ popFillNew.notify({'msg':'Comment is too long.','overwrite':true}); commentbox.value = ''; commentbox.disabled = false; }else if(comment.length > 3){ if(comment != 'Saving comment...'){ window.speech.saveCommentResponse = this.saveCommentResponse; window.speech._serverRequests(['server/files.php'],{"itemid":id,"stamp":stamp,"comment":comment,"userid":window.USERDATA.userid}); } jpmplayer.updateRequests(); }else { popFillNew.notify({'msg':'Comment is too short.','overwrite':true}); commentbox.value = ''; commentbox.disabled = false; } } getComments(itemid){ window.speech.getcommentsResponse = function(d){ if(document.getElementById(`imgcomments-${itemid}`)){ if(d != ''){ let commenthtml = ``; if(d.payload.length > 0){ d.payload.forEach(function(x,i){ x.comment = x.comment.replaceAll('\n','
'); let isoString = new Date(x.userstime * 1000).toISOString(); const localDate = new Date(isoString); const dated = localDate.toLocaleString(); const userimg = x.profileimg != '' && x.profileimg != null ? `` : ''; commenthtml += `
${userimg}
${x.user}
${x.comment}
`; }); }else { commenthtml += `Post a comment above.`; } document.getElementById(`imgcomments-${itemid}`).innerHTML = commenthtml; //$("time.timeago").timeago(); } } }; if(document.getElementById(`imgcomments-${itemid}`)){ //
document.getElementById(`imgcomments-${itemid}`).innerHTML = '
Loading comments...
'; window.speech._serverRequests(['server/files.php'],{"getcomments":itemid}); } } loadComments(){ document.getElementById("profilefeed").innerHTML = `
`; this.getComments(window.userid); } contentLoaded(){ if(document.getElementById("profilefeed")){ this.loadComments(); } } iniContent(){ let title = this.title, showItem = this.showItem; const userp = this.searchParams.get('u'), searchParams = this.searchParams; this.userp = userp; if(document.getElementById('gallerytitle')){ if(title != ''){ title = decodeString(title); document.getElementById('gallerytitle').innerHTML = title; } } if(this.listid == ''){ if(PUBLICLIST[0] !== undefined){ this.listid = PUBLICLIST[0].list; } } if(this.listid != ''){ document.getElementById("sortoptions").innerHTML = ``; document.getElementById("changeview").innerHTML = ``; } this.resizeObserver = new ResizeObserver((entries) => { for(const entry of entries) { const { width, height } = entry.contentRect; console.log(`Div resized! Current size: ${width}px x ${height}px`); } }); window.resizeTimer = null; window.addEventListener('resize', () => { clearTimeout(window.resizeTimer); window.resizeTimer = setTimeout(() => { //console.log(`Width: ${window.innerWidth}, Height: ${window.innerHeight}`); if(document.getElementById("easyload")){ document.getElementById("easyload").innerHTML = ''; document.getElementById("easyload").style.width = '100%'; window.easyLoader=true; loadList(window.dDx.backto-1); } //window.document.body.scrollTop = window.document.documentElement.scrollTop = 0; }, 250); }); } itemLoaded(itemid,listid,type,elem) { if(type == '*file' || type == '*video' || type == 'youtube' ){ jpmplayer.removeLoader(''+itemid+'',''+listid+'',type,elem); } if(type == '*apiimg'){ //if(elem.clientHeight != 0) } } imgLoaded(items,elem,count,endat,itemx) { let lib = this; let newcount = count+1; const dsize = items.length; //insert img elem.style.display = 'block'; const div = document.createElement("div"); const ahref = document.createElement("a"); let mediax = (itemx.original !== undefined) ? itemx.original : itemx.media; if(itemx.type == 'flickr'){ mediax = mediax.replace("_m","_b"); } let imgsrcx = itemx.mediax !== undefined ? itemx.media : mediax; imgsrcx = itemx.thumbnail !== undefined ? itemx.thumbnail : imgsrcx; imgsrcx = imgsrcx !== undefined ? imgsrcx : '../images/couldnotload.png'; let nextitem = items[count+1] !== undefined ? items[count+1].id : ''; let previtem = items[count-1] !== undefined ? items[count-1].id : ''; ahref.setAttribute("onclick",'popFillNew.exe({\'onload\':\'onShowBox\',\'once\':1,\'elem\':\'#iframe-'+itemx.id+'\',\'content\':window.pjui.html.iframe,\'elemclass\':\'ytiframe\',\'data\':this})'); ahref.setAttribute("href","javascript:void(0)"); ahref.setAttribute("data-ext",itemx.tld); if(itemx.type != 'file') ahref.setAttribute("data-media",imgsrcx); ahref.setAttribute("data-type",itemx.type); ahref.setAttribute("data-path",'../data/files/'); ahref.setAttribute("id",'openicon-'+itemx.id+''); ahref.setAttribute("data-listin",''+itemx.list+''); ahref.setAttribute("data-itemid",''+itemx.id+''); ahref.setAttribute("data-navigate",''+nextitem+'|'+previtem+''); div.setAttribute("style","display:flex;justify-content:center;align-items:center;width:"+this.maxwidth+"px;background:#333"); div.style.position = 'absolute'; if(this.rowon == 1){ div.style.top = '0'; div.style.left = this.totalrowwidth+'px'; }else { div.style.top = (this.itemsheight[this.elcolumnon-1] - 1)+'px'; div.style.left = this.totalrowwidth+'px'; } $(ahref).append(elem); $(div).append(ahref); $("#easyload").append(div); // + 10 to add margin etc. (elem.clientWidth) this.totalrowwidth = this.maxwidth + this.totalrowwidth; if(this.itemsheight[this.elcolumnon-1] === undefined){ this.itemsheight[this.elcolumnon-1] = 0; } if(elem.clientHeight != 0){ this.itemsheight[this.elcolumnon-1] = (elem.clientHeight + this.itemsheight[this.elcolumnon-1]); } let current = ''; for(let i=0;i < this.itemsheight.length;i++){ if(i > 0){ if(this.itemsheight[i] > current){ current = this.itemsheight[i]; } }else { current = this.itemsheight[i]; } } $("#easyload").css({"height":current+"px"}); $("#footer").css({"display":"block"}); // new row if(this.elcolumnon >= this.elcolumns){ this.elcolumnon = 0; this.rowon = this.rowon + 1; this.totalrowwidth = 0; console.log(this.elcolumns + ' new row '+ newcount + ' '+ this.itemsheight); } this.elcolumnon++; if(!this.preview && this.showItem == '' && dsize == newcount){ $("#backbutton").html('
'); } if(items[newcount] !== undefined && endat > newcount){ // show/process only images etc. for(var i = newcount;i { imgelem2.src = '../images/couldnotload.png'; }); imgelem2.addEventListener('load', (event) => { lib.imgLoaded(items,imgelem2,newcount,endat,item); }); } } processContent(item,items,hits,i) { const showItem = this.showItem; let ftype = item.type, html = '', media = (item.original !== undefined) ? item.original : item.media, fileext = item.tld, allhitsx = (hits[item.id] !== undefined) ? hits[item.id] : 0, favorite = '', extendicons = ''; if(showItem !== ''){ if(item.id != showItem){ return; } extendicons = ''; } if(!this.preview){ favorite = `
${extendicons}Favourite
`; } let allhits = '

'+allhitsx+' views

'+favorite+''; let allhits2 = '

'+allhitsx+' downloads

'+favorite+''; let nextitem = items[i+1] !== undefined ? items[i+1].id : ''; let previtem = items[i-1] !== undefined ? items[i-1].id : ''; item.title = decodeString(item.title); let author = ''; if(item.title !== undefined){ author = item.author !== undefined ? item.author : author; let xtitle = item.title; if(xtitle.length > 119){ let origtitle = item.title.trim(); item.title = origtitle.substring(0, 120)+'...'; } let xauthor = author != '' ? author : xtitle; if(xauthor.length > 70){ xauthor = xauthor.trim().substring(0, 70)+'...'; } if(xtitle.length > 70){ xtitle = xtitle.trim().substring(0, 70)+'...'; } if(item.type == 'reddit'){ //https://www.reddit.com/user/'+author+'/ author = ''+xtitle+''; }else if(item.type == 'flickr'){ // https://www.flickr.com/photos/'+author+'/ author = ''+xtitle+''; }else if(item.type == 'youtube'){ author = item.url !== undefined ? ''+item.title+'' : 'Untitled'; }else if(author.includes("http") || author.includes("www")){ author = ''+item.title+''; }else { if(item.type == 'amazon'){ extendItemURL = '?th=1&psc=1&linkCode=ll1&tag=playlistjungl-20&language=en_US&ref_=as_li_ss_tl'; item.url = item.url.slice(0, -1) + extendItemURL; } author = item.url !== undefined ? ''+xauthor+'' : xauthor; } author = "

" + author + "

"; } let imgelem = ''; ////////////////////////////////// // API content ///////////////////////////////// if(ftype == 'googleimgs' || ftype == 'yandeximgs' || ftype == 'bingimgs' || ftype == 'yahooimgs' || ftype == 'ebay' || ftype == 'googleshop' || ftype == 'yahooshop' || ftype == 'homedepot' || ftype == 'walmart' || ftype == 'reddit' || ftype == 'amazon' || ftype == 'flickr' || item.type == '*url'){ let imgsrc = item.media !== undefined ? item.media : media; imgsrc = item.thumbnail !== undefined ? item.thumbnail : imgsrc; imgsrc = imgsrc !== undefined ? imgsrc : '../images/couldnotload.png'; if(ftype == 'flickr'){ media = media.replace("_m","_b"); } if(ftype == '*url'){ item.type = 'googleimgs'; } let itemprice = (ftype == 'ebay') && item.price !== undefined || (ftype == 'googleshop' || ftype == 'yahooshop' || ftype == 'amazon' || ftype == 'walmart' || ftype == 'homedepot') && item.price !== undefined ? ' ' + item.price : ''; imgelem = `snapshot.jpg`; html += '
'+imgelem+''+author+' '+itemprice+' '+allhits+'
'; } else if(fileext == 'webp' || fileext == 'jpeg' || fileext == 'gif' || fileext == 'bmp' || fileext == 'png' || fileext == 'jpg'){ imgelem = `snapshot.jpg`; html += '
'+imgelem+'

'+item.title+'

'+allhits+'
'; }else if(ftype == 'youtube'){ imgelem = `snapshot.jpg`; html += '
'+imgelem+''+author+' '+allhits+'
'; }else if(item.type == '*video'){ imgelem = `snapshot.jpg`; html +='
'+imgelem+'

'+item.title+'

'+allhits+'
'; }else if(item.type == '*file') { if(item.tld == 'txt' || item.tld == 'html'){ html +='
'+item.title+' ('+item.tld+')

'+item.title+'

'+allhits2+'
'; }else { html +='
'+item.title+' ('+item.tld+')

'+item.title+'

'+allhits2+'
'; } }else if(item.type == '*audio') { html +='

'+item.title+'

'+allhits2+'
'; } return html; } buildIt(){ console.log(this.sort); if(this.sort == 'views'){ let allhitsxx = 0; for(var i = 0;i
').insertBefore("#content"); }else { if(!this.append){ document.getElementById("easyload").innerHTML='
'; } } //this.resizeObserver.observe(); this.elcolumns = Math.floor(parseInt(document.getElementById("easyload").clientWidth) / this.maxwidth); document.getElementById("easyload").style.width = (this.elcolumns * this.maxwidth)+'px'; document.getElementById("easyload").style.margin = '20px auto'; console.log(this.elcolumns); if(!this.append){ this.itemsheight = []; this.elcolumnon = 1; this.rowon = 1; } this.elcolumnon = 1; this.totalrowwidth = 0; if(this.itemsheight[this.elcolumnon-1] === undefined){ this.itemsheight[this.elcolumnon-1] = 0; } const imgelem2 = document.createElement("img"); imgelem2.style.maxWidth = this.maxwidth+"px"; imgelem2.style.height = "auto"; /* let k = 0 for(var i = startat;i { lib.imgLoaded(items,imgelem2,startat,endat,item); }); } this.contentLoaded(); return html; } for(var i = this.startat;i])*(>|$)/g, ""); } if(this.showItem !== ''){ if(item.id != this.showItem){ continue; console.log(item.id,this.showItem); } } let helper = this.helper; // prep let x = view.replaceAll(/\{(.*?)\}/g,function(match) { let c = match.replace(/\{(.*?)\}/g,'$1'); let temphold = ''; if(typeof(helper) == 'function'){ temphold = helper(item,c,i+1); } //if(typeof(item[c]) != 'undefined'){ return temphold; //}else { //return `{${c}}`; //} }); html += `${x}`; let perrowd = perrow - 1; // show all gallery if(this.preview && (i == perrowd && dsize != i+1 )){ //
html +='

'; break; }else { //console.log(dsize,i); if(!this.preview && dsize == i+1 && this.showItem == ''){ html +='
'; } } if(i == this.endat){ break; } if(this.showItem !== ''){ if(item.id == this.showItem){ break; } } } } const cdiv = document.getElementById(this.filldiv); cdiv.style.display = 'grid'; this.contentLoaded(); return html; }; buildGallery(sort='date',startat=0,endat=0,preview=false,append=false,backto=1){ this.sort = sort; this.startat = startat; this.endat = endat; this.preview = preview; this.append = append; if(endat == 0){ this.endat = dDx.easyload ? 43 : 23; } const html = this.buildIt(); if(this.append){ $("#"+this.filldiv).append(html); }else { document.getElementById(this.filldiv).innerHTML = this.view2+html; window.document.body.scrollTop = window.document.documentElement.scrollTop = 0; } this.loadMore(); this.append = false; } loadMore(insert=false){ $("#loadmorelists").css({"display":"block"}); let fillit = ''; console.log(dDx.easyload) const perpage = dDx.easyload ? 44 : 24; const perpage2 = dDx.easyload ? 45 : 25; const perpagex = dDx.easyload ? 88 : 48; const perpage_ = dDx.easyload ? 43 : 23; if(!this.preview && this.showItem == ''){ if(!insert){ const loadmorelists = document.getElementById("loadmorelists"); } let startattxt = (this.startat + 1); let endattxt = (this.endat + 1); if((this.endat+1) < this.dsize){ this.startat = (this.endat + 1); this.endat = (this.endat + perpage); let prestartat = (this.startat - perpagex); let preendat = (this.startat - perpage2); let prevb = '', tolast = ''; const tstart = Math.floor(this.dsize / perpage) * perpage; const tend = (Math.ceil(this.dsize / perpage) * perpage) - 1; if(this.dsize > perpagex){ tolast = ` `; } if(this.startat > perpage && preendat > 2){ prevb = ``; } fillit = `
${startattxt} - ${endattxt} of ${this.dsize} total
`; if(!insert){ loadmorelists.innerHTML = fillit; } }else { this.startat = (this.endat + 1); this.endat = (this.endat + perpage); let prestartat2 = (this.startat - perpagex); let preendat2 = (this.startat - perpage2); let prevb2 = ''; if(this.startat > perpage && preendat2 > 2){ prevb2 = ``; } if(this.dsize < perpage2){ fillit = ''; }else { fillit = `
${startattxt} - ${this.dsize} of ${this.dsize} total
`; } if(!insert){ loadmorelists.innerHTML = fillit; } } if(insert){ return fillit; } } return fillit; } static get defaultConfig() { return {}; }; }