HumAnTarg3t / twitchParasocial_Logger

Other
0 stars 1 forks source link

cap how many messages are in the HTML DOM #17

Open HumAnTarg3t opened 6 months ago

HumAnTarg3t commented 6 months ago

should be okay now.

    function deleteMessages(div, numofMessages) {
      try {
        // Get all paragraphs into an HTMLCollection
        const paragraphs = div.getElementsByTagName("p");
        const numOfParaToDelete = 4;
        const numOfMSGToDelete = numOfParaToDelete * (numofMessages / 2);

        // Convert HTMLCollection to an array
        const paragraphArray = Array.from(paragraphs);
        // console.log(paragraphArray[0]);

        // Get the number of paragraphs
        const numParagraphs = paragraphArray.length;
        // console.log(numParagraphs);

        if (numParagraphs > numofMessages * numOfParaToDelete) {
          for (let index = 0; index < numOfMSGToDelete; index++) {
            div.removeChild(paragraphArray[index]);
          }
        }
      } catch (error) {
        console.log("prob not enough to del");
        console.log(error);
      }
    }

Deletes for all streames at the same time (if (numParagraphs > numofMessages * numOfParaToDelete) )