F95 Game Post Only

Display only the 1st post of a game thread. This completely removes all replies (and more) from the thread.

// ==UserScript==
// @name        F95 Game Post Only
// @namespace   1330126-edexal
// @match       *://f95zone.to/threads/*
// @grant       none
// @icon        https://external-content.duckduckgo.com/ip3/f95zone.to.ico
// @license     Unlicense
// @version     1.1.1
// @author      Edexal
// @description Display only the 1st post of a game thread. This completely removes all replies (and more) from the thread.
// ==/UserScript==
(async function(){

  function deleteEls(el){
    if (el instanceof NodeList){
      el.forEach((curVal,curIndex)=>{
        curVal.remove();
      });
    } else if (el instanceof Element) {
      el.remove();
    }else{
      console.error(`Unable to delete ${el}! Element is of type: ${typeof el}.`);
    }
  }

   async function removeFooter(){
    let footer = document.querySelector("#footer");
    await deleteEls(footer);
  }

  async function removeBreadcrumbs(){
    let breadcrumb = document.querySelectorAll(".breadcrumb");
    await deleteEls(breadcrumb);
  }

  async function removeAccountItems(){
    let accIcon = document.querySelector("a.p-navgroup-link--user, .offCanvasMenu");
    await deleteEls(accIcon);
  }

  async function removeReplyItems() {
    let replyForm = document.querySelector('form.js-quickReply');
    await !!replyForm ? deleteEls(replyForm) : null;

    let replyActions = document.querySelectorAll('a.actionBar-action--mq,  a.actionBar-action--reply');
    await !!replyActions ? deleteEls(replyActions) : null;
  }

  async function removeRecomendations() {
    let recomendationSection = document.querySelector('div.block--similarContents');
    await !!recomendationSection ? deleteEls(recomendationSection) : null;
  }

  async function showFirstPostOnly() {
    //Thread Post Container Ref
    let opContainer = document.querySelector("article.message-threadStarterPost").parentNode;
    opContainer.replaceChildren(opContainer.children.item(0));

    let paginations = document.querySelectorAll('.pageNavWrapper--mixed');
    //top pagination
    let topPageContainer = paginations[0].parentNode.parentNode;
    await !!topPageContainer ? deleteEls(topPageContainer) : null;

    //bottom pagination
    let bottomPageContainer = paginations[1].parentNode.parentNode;
    await !!bottomPageContainer ? deleteEls(bottomPageContainer) : null;

    //Scrollbar buttons
    let scrollbarContainer = document.querySelector('div.u-scrollButtons').parentNode;
    await !!scrollbarContainer ? deleteEls(scrollbarContainer) : null;
  }

  function isGameThread(){
    let breadcrumbID = document.querySelectorAll("ul.p-breadcrumbs li:nth-of-type(3) a span[itemprop=name]");
    let isGame = false;
    if (!!breadcrumbID.length){
      breadcrumbID.forEach((curVal, curIndex) => {
        if (curVal.textContent.toLowerCase() === "Games".toLowerCase()){
          isGame = true;
        }
      });
    }
    return isGame;
  }

  /*Checks if thread is a GAME type*/
  if(isGameThread()){
    await showFirstPostOnly();//
    /*-----------------------(Optional) Delete '//' for each option to activate----------------*/
    await removeBreadcrumbs();
    await removeFooter();
    await removeRecomendations();//Removes the similar threads section at the bottom of the page
    await removeReplyItems();//Removes reply related elements from the page
    //await removeAccountItems();
  }

})().catch((err)=> console.error(err));