rejetto forum

Custom folder previews

D · 7 · 959

0 Members and 1 Guest are viewing this topic.

Offline D

  • Occasional poster
  • *
    • Posts: 17
    • View Profile
Let's say I have following folders

New folder
New folder 2
New folder 3

Each contains a "p.jpg", I want to use these as folder preview. Attached an example

The code for diff template I'm currently using:
Code: [Select]
[+]
<script>
var list=document.querySelectorAll("table#files>tbody>tr");
function changepic(a1)
{
  var alink=a1.querySelector("a");
  var adress=alink.getAttribute("href");
  if(adress.endsWith("/"))
  {
  adress+="p.jpg";
  var img=document.createElement("img");
  img.setAttribute("src",adress);
  img.setAttribute("onerror","this.style.display='none'");
  a1.children[3].appendChild(img);
  }
}
list.forEach(changepic);
</script>
eats too much cpu if there are too many folders. Because script doesn't check if p.jpg is actually present in folder

How can I fix it? Thanks in advance.
« Last Edit: September 15, 2021, 09:45:20 AM by D »


Offline D

  • Occasional poster
  • *
    • Posts: 17
    • View Profile
Okay, variant with images behind buttons:
Code: [Select]
[+]
<script>
var list=document.querySelectorAll("table#files>tbody>tr");
function changepic(a1)
{
  var alink=a1.querySelector("a");
  var adress=alink.getAttribute("href");
  if(adress.endsWith("/"))
  {
  adress+="p.jpg";
  var button=document.createElement("button");
  button.setAttribute("onclick","showPreview(this)");
  button.setAttribute("link",adress);
  button.setAttribute("type","button");
  a1.children[3].setAttribute("style","text-align:center");
  a1.children[3].appendChild(button);
  button.appendChild(document.createTextNode("Preview"));
  } 
}
list.forEach(changepic);
function showPreview(butt)
{
  butt.setAttribute("style","display:none");
  var par=butt.parentElement;
  var img=document.createElement("img");
  img.setAttribute("src",butt.getAttribute("link"));
  par.appendChild(img);
}
</script>


Offline dj

  • Tireless poster
  • ****
    • Posts: 280
  • 👣 🐾
    • View Profile
    • PWAs
for hfs2.4

Code: [Select]
[+]
<script>
function folderth(){
 [...document.querySelectorAll('#files a[href$="/"]')].forEach(item =>
 item.insertAdjacentHTML('afterend', '<img loading=lazy height=128 src='+item.href+'folder.jpg>')  //p.jpg
 )
}

if(!document.querySelector('main')) folderth()  //hfs2.4
else document.addEventListener('render', folderth)  //mobil-light_V5.6
</script>
« Last Edit: September 15, 2021, 08:32:30 AM by dj »


Offline D

  • Occasional poster
  • *
    • Posts: 17
    • View Profile

Offline D

  • Occasional poster
  • *
    • Posts: 17
    • View Profile
The question is still relevant, can someone help, please?


Offline Owais Baloch

  • Occasional poster
  • *
    • Posts: 25
  • ;) :*
    • View Profile
    • Facebook link ;)
Thanks. How can I move these images into Hits column?

[folder]
<div class="item folder {.if not|{.or|{.get|can archive.}|{.get|can delete.}.}| off .}"
    item-access="{.if|{.get|can access.}| You can access this item! | This item is protected. .}"
    item-added="%item-added%"
    item-dl-count="%item-dl-count%"
    item-comment="{.replace|>| &gt; |<| &lt; |"|"|%item-comment%.}">
   <a href="%item-url%" title="Click to Enter">

      <p align="center">

      <img src="%item-url%folder.png" style="width:256px;height:258px"/>
      </p>


      {.if|{.get|is new.}|<img class="new" src="/template/{.!theme.}/images/new.png" alt=""/>.}
   </a>
      <div><a href="%item-url%" title="Click to Enter"># %item-name% #</a>
<address>
&nbsp; </address>


   <address>Hit Count:<font color="#00bcd4"><b> %item-dl-count%  </b></font></address>


   Added: <span>
<font color="#FFF"><b> %item-modified% </b></font></span>


</div>
</div>