Reddit comment collector

gether all comments from a reddit post

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @icon          https://www.reddit.com/favicon.ico
// @name          Reddit comment collector
// @author        grefork
// @description   gether all comments from a reddit post
// @match         *://www.reddit.com/r/*/comments/*
// @version       1.4.1
// @namespace     grefork
// @require       http://code.jquery.com/jquery-3.4.1.min.js
// @grant    GM_addStyle
// ==/UserScript==
{
    const commentClass = "._1qeIAgB0cPwnLhDF9XSiJM";
    const insertClass = "._1r4smTyOEZFO91uFIdWW6T";
    const init = async () => {
    try {
      if($(insertClass).get().length ==0) throw new Error('Wait for loading')

      function getComments() {
          if ($("#commentList").get().length > 0)
              return
          const textList = $(commentClass)
          var commentList = [];
          for (var i=0;i<textList.length;i++) {
              if(textList[i].textContent.includes("http"))
                  continue;
              var splitted = textList[i].textContent.split(/[.?!。]+/);
              console.log(splitted)
              for (var j=0; j<splitted.length; j++){
                  if(splitted[j].length > 5 && !commentList.includes(splitted[j]))
                      commentList.push(splitted[j].trim());
              }
          }
          var textarea = document.createElement("textarea");
          textarea.id = "commentList";
          textarea.value = commentList.join("\n");
          textarea.style.cssText = "width:100%;height:200px"
          $(insertClass).get()[0].appendChild(textarea);
      }

      var button = document.createElement("button");
      button.innerText = "LOAD COMMENT";
      button.style.cssText = "background-color:#327bb3;padding:5px"
      button.onclick = getComments
      $(insertClass).get()[0].appendChild(button);

    } catch (_) {
      setTimeout(init, 1000);
    }
  };
  init();
}