"view replies" auto expander

click on "view replies (500)" and it will click on the same button until all replies open.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         "view replies" auto expander
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  click on "view replies (500)" and it will click on the same button until all replies open.
// @author       goodwin64
// @match        *://instagram.com/*
// @match        *://www.instagram.com/*
// @namespace    instagram.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const markedElements = new Set();

    function listenToExpandClicks() {
      [...document.getElementsByTagName('span')]
        .filter(el => el.innerText.toLowerCase().includes('view'))
        .forEach(el => {
          if (!markedElements.has(el)) {
            el.addEventListener('click', handleViewRepliesClick);
            markedElements.add(el);
          }
        });
    }
    
    function howMuchRepliesLeft(str) {
      const repliesCountMatch = str.match(/.*\((\d*)\)/)
      return repliesCountMatch ? Number(repliesCountMatch[1]) : 0;
    }
    
    function handleViewRepliesClick() {
      clickIfExpandable(this);
    }
    
    function clickIfExpandable(el) {
      const repliesLeft = howMuchRepliesLeft(el.innerText);
      if (repliesLeft > 0) {
        el.click();
        setTimeout(() => {
          clickIfExpandable(el);
        }, 1000);
      } else {
        el.removeEventListener('click', handleViewRepliesClick);
        markedElements.delete(el);
      }
    }
    
    setInterval(listenToExpandClicks, 3000);
})();