Skip to content

Instantly share code, notes, and snippets.

@ixtk
Created June 2, 2025 06:18
Show Gist options
  • Save ixtk/28921a4b609d7519a39052fbd708b524 to your computer and use it in GitHub Desktop.
Save ixtk/28921a4b609d7519a39052fbd708b524 to your computer and use it in GitHub Desktop.

ul-ს დაუწერე list-style-position: inside;

site-main-ს ზედმეტი margin-top აქვს

ფონტი იყოს sans-serif

line-height: 1.4 body-ზე

if (SW) {
  SW.onclick = function () {
    if (SW.classList.contains("active")) {
      SW.classList.remove("active");
      SW.classList.add("deactive");
      body.classList.remove("black");
      body.classList.add("white");
    } else {
      SW.classList.remove("deactive");
      SW.classList.add("active");
      body.classList.remove("white");
      body.classList.add("black");
    }
  };
}

ეს შეგიძლია classList.toggle-ითაც დაწერო. SW-ს გადაარქვი სახელი და უფრო კონკრეტული დაარქვი.

const body = document.querySelector("body");

selector არც გინდა აქ, პირდაპირ დაწერე document.body სადაც დაგჭირდება

mainElement.style.display = "none";
footer.style.display = "none";

ესენი გვერდის ჩატვირთვისას გიწერია JS-ში, ამიტომ ჯობს CSS-ში გადაიტანო და საწყისად ორივეს დაუწერო display: none. ჯავასკრიპტი მანდ არ გვჭირდება

if (pouseIcon) pouseIcon.style.opacity = "1";

pauseIcon არ გაქვს არსად, ერორს აგდებს და ეს წაშალე. ასევე, ჯობია pouseBtn-იც display: none/block-ით დამალო/გამოაჩინო, ვიდრე opacity-ით მხოლოდ.

const firstMeaning = entry.meanings[0];

აქ მხოლოდ პირველი არა, ყველა უნდა წაიკითხო და თითოეულისთვის (noun, verb, adjective...) შექმნა meaning list-ები (for loop)

while (meaningList.firstChild) {
  meaningList.removeChild(meaningList.firstChild);
}

ასეთი ციკლის ნაცვლად პირდაპირ დაწერე meaningList.innerHTML = '' ფუნქციის დასაწყისში რომ სია გაასუფთავო ;

let synonymsSet = new Set();
entry.meanings.forEach((meaning) => {
  if (meaning.synonyms && meaning.synonyms.length) {
    meaning.synonyms.forEach((syn) => synonymsSet.add(syn));
  }
  if (meaning.definitions && meaning.definitions.length) {
    meaning.definitions.forEach((def) => {
      if (def.synonyms && def.synonyms.length) {
        def.synonyms.forEach((syn) => synonymsSet.add(syn));
      }
    });
  }
});

ეს არაა საჭირო. შენ ციკლს უშვებ და სინონიმებს და definition-ებს ცალკე სეტში ინახავ, მაგრამ API უკვე გვიბრუნებს სიას, აღარაა საჭირო რომ სეტად გადააკეთო. პირდაპირ დაწერ აი აქ

firstMeaning.definitions.forEach((def) => {
  const li = document.createElement("li");
  li.className = "meaning-item";
  li.textContent = def.definition;

  // მერე ეს ელემენტად შეინახე და DOM-ში გამოაჩინე
  console.log(def.synonyms.join(', '))

  meaningList.appendChild(li);
});

როგორც დიზაინშია, example-ებიც გაკლია HTML-ში

pouseBtn.onclick = function () {
  if (audio) {
    audio.currentTime = 0;
    audio.play();
  }
};

აქ აუდიოს ობიექტი არ შეგიქმნია, ასევე API-დან დაბრუნებული ლინკი უნდა გადასცე

და ბოლოს, აქ ნახე, თითქმის იგივე კოდს იმეორებ else-ში და catch-ში. ამიტომ ჯობია else-ში throw new Error("No definition found") დაწერო და catch-ში გადახტება კოდი თავისით და catch-ის კოდს გაუშვებს. ასევე catch()-ში არ გიწერია ერორი. ასე უნდა გეწეროს catch(error) და შეგიძლია მერე ნასროლი ერორის (throw new...) ან რამე სხვა ერორის მესიჯი წაიკითხო და დინამიურად დააყენო error.message, იმის ნაცვლად რომ ახლა ყველა ერორზე დაწერო "Word not found". while ციკლი აქაც ამოიღე.

} else {
    wordType.textContent = "";
    while (meaningList.firstChild) {
      meaningList.removeChild(meaningList.firstChild);
    }
    const li = document.createElement("li");
    li.className = "meaning-item";
    li.textContent = "No definitions found.";
    meaningList.appendChild(li);
    synonymList.textContent = "";
    sourceLink.textContent = "";
  }
})
.catch(() => {
  wordTitle.textContent = "Word not found";
  wordType.textContent = "";
  while (meaningList.firstChild) {
    meaningList.removeChild(meaningList.firstChild);
  }
  const li = document.createElement("li");
  li.className = "meaning-item";
  li.textContent = "No definitions found.";
  meaningList.appendChild(li);
  synonymList.textContent = "";
  sourceLink.textContent = "";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment