<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>coding &amp;mdash; berkough.com</title>
    <link>https://berkough.com/tag:coding</link>
    <description></description>
    <pubDate>Fri, 24 Apr 2026 19:50:44 +0000</pubDate>
    <image>
      <url>https://i.snap.as/fMfRWXNN.png</url>
      <title>coding &amp;mdash; berkough.com</title>
      <link>https://berkough.com/tag:coding</link>
    </image>
    <item>
      <title>Code for Top 20 Lists</title>
      <link>https://berkough.com/code-for-top-20-lists?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[#javascript #coding #journal&#xA;&#xA;Not too long ago, one of the members of the Pixel Pints shared with us a simple webapp that he found for building top-whatever lists, called Topsters.&#xA;&#xA;I decided to play around with it a bit, and, as I mentioned in the last post--which was itself a top 20 list--I wanted to have an overlay for links on top of the image, so it was more like a widget instead of just an image. The power of Topsters is not the image that it generates necessarily, but how easily you can generate the image by querying a bunch of APIs based on your media selection (books, albums, movies, or games). So, in that regard adding a little flare to the image seemed appropriate, and why not give it some interactivity? Topsters itself utilizes a canvas element to arrange the pictures of the book, album, movie, or game covers. I could always consider maybe doing that myself, or&#xA;!--more--&#xA;&#xA;As I&#39;ve mentioned, Write.as does give you a script area that you can use, and I don&#39;t think you can just inject JavaScript anywhere... I did try simply putting script tags in the markdown of a singular post, but it wasn&#39;t passing through when I inspected the live version of the site.&#xA;&#xA;The next best option was to write an if statement which launches a specific function to act on a specific div when certain conditions are met.&#xA;&#xA;You can clone from here, or simply take a look at the code:&#xA;&#xA;//Global Variables to use:&#xA;const path = document.location.pathname;&#xA;/--------------------------------------/&#xA;function albumNum() {&#xA;  let covers = document.getElementById(&#34;covers&#34;);&#xA;  covers.style = &#34;position: relative;&#34;;&#xA;&#xA;  for (let i = 1; i &lt;= 20; i++) {&#xA;    let numbers = a href=&#34;#item${i}&#34;p class=&#34;albNumber&#34; id=&#34;cover-${i}&#34;#${i}./p/a;&#xA;    covers.innerHTML += numbers;&#xA;&#xA;    setNumPos(i);&#xA;  }&#xA;}&#xA;&#xA;function setNumPos(num) {&#xA;  let displayedNumber = document.getElementById(cover-${num});&#xA;&#xA;  let imgHeight = covers.getElementsByTagName(&#34;img&#34;)[0].height;&#xA;  console.log(imgHeight);&#xA;  let imgWidth = covers.getElementsByTagName(&#34;img&#34;)[0].width;&#xA;  console.log(imgWidth);&#xA;&#xA;  let row = [&#xA;    imgWidth  0.25, &#xA;    imgWidth  0.5, &#xA;    imgWidth - imgWidth  0.25&#xA;  ];&#xA;  let col = [&#xA;    imgHeight  0.02,&#xA;    imgHeight  0.23,&#xA;    imgHeight  0.43,&#xA;    imgHeight  0.63,&#xA;    imgHeight  0.83&#xA;  ];&#xA;&#xA;  console.log(&#34;Widths &#34; + row);&#xA;  console.log(&#34;Heights &#34; + col);&#xA;&#xA;  switch (num) {&#xA;    case 1:&#xA;      displayedNumber.style = position: absolute; top: ${col[0]}px; left: 0px;;&#xA;      break;&#xA;    case 2:&#xA;      displayedNumber.style = position: absolute; top: ${col[0]}px; left: ${row[0]}px;;&#xA;      break;&#xA;    case 3:&#xA;      displayedNumber.style = position: absolute; top: ${col[0]}px; left: ${row[1]}px;;&#xA;      break;&#xA;    case 4:&#xA;      displayedNumber.style = position: absolute; top: ${col[0]}px; left: ${row[2]}px;;&#xA;      break;&#xA;    case 5:&#xA;      displayedNumber.style = position: absolute; top: ${col[1]}px; left: 0px;;&#xA;      break;&#xA;    case 6:&#xA;      displayedNumber.style = position: absolute; top: ${col[1]}px; left: ${row[0]}px;;&#xA;      break;&#xA;    case 7:&#xA;      displayedNumber.style = position: absolute; top: ${col[1]}px; left: ${row[1]}px;;&#xA;      break;&#xA;    case 8:&#xA;      displayedNumber.style = position: absolute; top: ${col[1]}px; left: ${row[2]}px;;&#xA;      break;&#xA;    case 9:&#xA;      displayedNumber.style = position: absolute; top: ${col[2]}px; left: 0px;;&#xA;      break;&#xA;    case 10:&#xA;      displayedNumber.style = position: absolute; top: ${col[2]}px; left: ${row[0]}px;;&#xA;      break;&#xA;    case 11:&#xA;      displayedNumber.style = position: absolute; top: ${col[2]}px; left: ${row[1]}px;;&#xA;      break;&#xA;    case 12:&#xA;      displayedNumber.style = position: absolute; top: ${col[2]}px; left: ${row[2]}px;;&#xA;      break;&#xA;    case 13:&#xA;      displayedNumber.style = position: absolute; top: ${col[3]}px; left: 0px;;&#xA;      break;&#xA;    case 14:&#xA;      displayedNumber.style = position: absolute; top: ${col[3]}px; left: ${row[0]}px;;&#xA;      break;&#xA;    case 15:&#xA;      displayedNumber.style = position: absolute; top: ${col[3]}px; left: ${row[1]}px;;&#xA;      break;&#xA;    case 16:&#xA;      displayedNumber.style = position: absolute; top: ${col[3]}px; left: ${row[2]}px;;&#xA;      break;&#xA;    case 17:&#xA;      displayedNumber.style = position: absolute; top: ${col[4]}px; left: 0px;;&#xA;      break;&#xA;    case 18:&#xA;      displayedNumber.style = position: absolute; top: ${col[4]}px; left: ${row[0]}px;;&#xA;      break;&#xA;    case 19:&#xA;      displayedNumber.style = position: absolute; top: ${col[4]}px; left: ${row[1]}px;;&#xA;      break;&#xA;    case 20:&#xA;      displayedNumber.style = position: absolute; top: ${col[4]}px; left: ${row[2]}px;;&#xA;  }&#xA;}&#xA;&#xA;if (path !==&#39;/&#39; &amp;&amp; document.querySelector(&#34;#covers&#34;)) {&#xA;  setTimeout(() =  {&#xA;    albumNum();&#xA;  }, 500);&#xA;}&#xA;&#xA;I need to do a bunch of stuff to this code;&#xA;re-write the switch statement as a function that checks for the number of rows and columns; and&#xA;re-write the for loop&#39;s iteration condition to be the rows multiplied by the columns.&#xA;&#xA;I&#39;m thinking I can signify by either reading the image file name, or using the id or class attributes.&#xA;&#xA;The cool thing is that I can put it anywhere and the image will render.&#xA;div id=&#34;covers&#34;&#xA;&#xA;/div&#xA;Watch out for more on this stuff. I&#39;ll might work on coming up with a format for the code so that I can start to chain blocks and widgets together. Also, I posted in the official forums, so I&#39;m curious what others have to say about my approach.]]&gt;</description>
      <content:encoded><![CDATA[<p><a href="https://berkough.com/tag:javascript" class="hashtag"><span>#</span><span class="p-category">javascript</span></a> <a href="https://berkough.com/tag:coding" class="hashtag"><span>#</span><span class="p-category">coding</span></a> <a href="https://berkough.com/tag:journal" class="hashtag"><span>#</span><span class="p-category">journal</span></a></p>

<p>Not too long ago, one of the members of the <a href="https://www.twitch.tv/pixelpints">Pixel Pints</a> shared with us a simple webapp that he found for building top-<em>whatever</em> lists, called <a href="https://topsters.org/">Topsters</a>.</p>

<p>I decided to play around with it a bit, and, as I mentioned in the last post—which was itself a top 20 list—I wanted to have an overlay for links on top of the image, so it was more like a widget instead of just an image. The power of Topsters is not the image that it generates necessarily, but how easily you can generate the image by querying a bunch of APIs based on your media selection (books, albums, movies, or games). So, in that regard adding a little flare to the image seemed appropriate, and why not give it some interactivity? Topsters itself utilizes a canvas element to arrange the pictures of the book, album, movie, or game covers. I could always consider maybe doing that myself, or
</p>

<p>As I&#39;ve mentioned, Write.as does give you a script area that you can use, and I don&#39;t think you can just inject JavaScript anywhere... I did try simply putting script tags in the markdown of a singular post, but it wasn&#39;t passing through when I inspected the live version of the site.</p>

<p>The next best option was to write an if statement which launches a specific function to act on a specific div when certain conditions are met.</p>

<p>You can clone from <a href="https://github.com/berkough/berkoughcom-scripts">here</a>, or simply take a look at the code:</p>

<pre><code class="language-javascript">//Global Variables to use:
const path = document.location.pathname;
/*--------------------------------------*/
function albumNum() {
  let covers = document.getElementById(&#34;covers&#34;);
  covers.style = &#34;position: relative;&#34;;

  for (let i = 1; i &lt;= 20; i++) {
    let numbers = `&lt;a href=&#34;#item${i}&#34;&gt;&lt;p class=&#34;albNumber&#34; id=&#34;cover-${i}&#34;&gt;#${i}.&lt;/p&gt;&lt;/a&gt;`;
    covers.innerHTML += numbers;

    setNumPos(i);
  }
}

function setNumPos(num) {
  let displayedNumber = document.getElementById(`cover-${num}`);

  let imgHeight = covers.getElementsByTagName(&#34;img&#34;)[0].height;
  console.log(imgHeight);
  let imgWidth = covers.getElementsByTagName(&#34;img&#34;)[0].width;
  console.log(imgWidth);

  let row = [
    imgWidth * 0.25, 
    imgWidth * 0.5, 
    imgWidth - imgWidth * 0.25
  ];
  let col = [
    imgHeight * 0.02,
    imgHeight * 0.23,
    imgHeight * 0.43,
    imgHeight * 0.63,
    imgHeight * 0.83
  ];

  console.log(&#34;Widths &#34; + row);
  console.log(&#34;Heights &#34; + col);

  switch (num) {
    case 1:
      displayedNumber.style = `position: absolute; top: ${col[0]}px; left: 0px;`;
      break;
    case 2:
      displayedNumber.style = `position: absolute; top: ${col[0]}px; left: ${row[0]}px;`;
      break;
    case 3:
      displayedNumber.style = `position: absolute; top: ${col[0]}px; left: ${row[1]}px;`;
      break;
    case 4:
      displayedNumber.style = `position: absolute; top: ${col[0]}px; left: ${row[2]}px;`;
      break;
    case 5:
      displayedNumber.style = `position: absolute; top: ${col[1]}px; left: 0px;`;
      break;
    case 6:
      displayedNumber.style = `position: absolute; top: ${col[1]}px; left: ${row[0]}px;`;
      break;
    case 7:
      displayedNumber.style = `position: absolute; top: ${col[1]}px; left: ${row[1]}px;`;
      break;
    case 8:
      displayedNumber.style = `position: absolute; top: ${col[1]}px; left: ${row[2]}px;`;
      break;
    case 9:
      displayedNumber.style = `position: absolute; top: ${col[2]}px; left: 0px;`;
      break;
    case 10:
      displayedNumber.style = `position: absolute; top: ${col[2]}px; left: ${row[0]}px;`;
      break;
    case 11:
      displayedNumber.style = `position: absolute; top: ${col[2]}px; left: ${row[1]}px;`;
      break;
    case 12:
      displayedNumber.style = `position: absolute; top: ${col[2]}px; left: ${row[2]}px;`;
      break;
    case 13:
      displayedNumber.style = `position: absolute; top: ${col[3]}px; left: 0px;`;
      break;
    case 14:
      displayedNumber.style = `position: absolute; top: ${col[3]}px; left: ${row[0]}px;`;
      break;
    case 15:
      displayedNumber.style = `position: absolute; top: ${col[3]}px; left: ${row[1]}px;`;
      break;
    case 16:
      displayedNumber.style = `position: absolute; top: ${col[3]}px; left: ${row[2]}px;`;
      break;
    case 17:
      displayedNumber.style = `position: absolute; top: ${col[4]}px; left: 0px;`;
      break;
    case 18:
      displayedNumber.style = `position: absolute; top: ${col[4]}px; left: ${row[0]}px;`;
      break;
    case 19:
      displayedNumber.style = `position: absolute; top: ${col[4]}px; left: ${row[1]}px;`;
      break;
    case 20:
      displayedNumber.style = `position: absolute; top: ${col[4]}px; left: ${row[2]}px;`;
  }
}

if (path !==&#39;/&#39; &amp;&amp; document.querySelector(&#34;#covers&#34;)) {
  setTimeout(() =&gt; {
    albumNum();
  }, 500);
}
</code></pre>

<p>I need to do a bunch of stuff to this code;
– re-write the switch statement as a function that checks for the number of rows and columns; and
– re-write the for loop&#39;s iteration condition to be the rows multiplied by the columns.</p>

<p>I&#39;m thinking I can signify by either reading the image file name, or using the id or class attributes.</p>

<p>The cool thing is that I can put it anywhere and the image will render.
<div id="covers" id="covers">
<img src="https://i.snap.as/DnXDPaxu.png" alt=""/>
</div>
Watch out for more on this stuff. I&#39;ll might work on coming up with a format for the code so that I can start to chain blocks and widgets together. Also, I posted in the <a href="https://discuss.write.as/">official forums</a>, so I&#39;m curious what others have to say about my approach.</p>
]]></content:encoded>
      <guid>https://berkough.com/code-for-top-20-lists</guid>
      <pubDate>Wed, 11 Oct 2023 01:50:43 +0000</pubDate>
    </item>
  </channel>
</rss>