Erasure icon indicating copy to clipboard operation
Erasure copied to clipboard

Wait for each comment to be deleted before continuing.

Open MURPHYENGINEERING opened this issue 4 years ago • 1 comments
trafficstars

As available on the web store, the extension doesn't delete any comments for me. They're hidden and I see the popup in the corner, but when I refresh they all come back.

I tried adjusting the delays and batching, but it seems the only way I can reliably see every comment deleted is to wait for each one before continuing.

Here I watch the comment list for changes to detect when the deletion was successful. This slows the process down by a huge amount, but it works every time.

MURPHYENGINEERING avatar Sep 08 '21 21:09 MURPHYENGINEERING

Just checking the script, I made a few smaller changes than your commit and it seems to work for me. I increased the delay from 0 to 5000 and removed the "i++" increment to the list index. Can you try to paste this script in the js console and see if it works for you before I update it with either of our commits?

// try 0, then try increasing values. this is delay between comment deletions
var DELAY = 5000;

// if script ends but yt has more comments loading then increase this pause value.
// this provides 1 retry attempt between list updates. useful for slow cpu/network.
// (electronoob: 800 was the ideal value for my machine)
var PAUSE = 5000;

var myList = document.getElementsByClassName("YxbmAc");

// scroll to the bottom of the page
function autoScroll () {
  window.scrollTo({ left: 0, top: document.body.scrollHeight, behavior: "smooth" });
}

// check for available comments
function commentsAvailable2 () {
  var m = document.getElementsByClassName("YxbmAc");
  if(m.length > 0){
    console.log('erasure: %s comments are available.', m.length);
    return true;
  }
  return false;
}

/* This function clicks the delete button for both regular and 
   non-G-suite account users. */
function deleteClick(element, callback1){
  try{ 
    element.querySelectorAll(".VfPpkd-rymPhb-pZXsl")[1].click();
    setTimeout(callback1, DELAY);
  }
  catch{
    element.querySelectorAll(".VfPpkd-Bz112c-LgbsSe")[0].click();
    setTimeout(callback1, DELAY);
  }
}

/* Main function */
function main(i) {
  if(commentsAvailable2()) {
    deleteClick(myList[i], () => {
      //++i;
      if(myList.length > 1){
        main(i);
      }else {
        console.log("erasure: attempting to retry in %s ms",PAUSE);
        autoScroll();
        setTimeout(()=>{
          main(0);
        },PAUSE);
      }
    });
  } else {
    console.log("erasure: there are no comments, exiting.");
  }
}

main(0);

ian-campbell avatar Sep 09 '21 00:09 ian-campbell