Reddit comment collector

gether all comments from a reddit post

当前为 2020-10-20 提交的版本,查看 最新版本

// ==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.2
// @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.length > 5)
                  commentList.push(textList[i].textContent);
          }
          var textarea = document.createElement("textarea");
          textarea.id = "commentList";
          textarea.value = commentList.join("\n");
          $(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();
}