跪拜 Guibai
← Back to the summary

A `setInterval` Script Deleted 14 Pages of Social Posts While Its Author Played Mahjong Link

Background

A restless day. I glanced at the Juejin short posts I'd posted before and felt they read like the cringey Qzone logs I wrote back in school.

So I thought I'd delete some — otherwise I'd be exposing my true nature of loving to mess around.

Then I opened "Creator Center" - "Content Management" - "Short Post Management" and patiently deleted them one by one…

Two minutes passed. I looked at the 14 remaining pages of short posts…

I was numb.

Figure 1.png

Analysis

As a programmer, I felt I couldn't keep doing this…

So I did the following:

Figure 2.gif

Figure 3.png

Execution

The next steps were simple. I just needed to do this, then that, and finally this — and it should work.

Haha, no more nonsense. Let's first do this in the browser:

// Try running this in the console
document.getElementsByClassName('byte-dropdown-item')[0].click();

Figure 4.gif

Then, continue like this:

// After the popup appears, run the following code
document.getElementsByClassName('btn-confirm')[0].click();

Figure 5.gif

Finally, the short post disappeared.

Optimization

Two lines of code saved me half a minute of clicking, but it was still tiring.

As a programmer, I had to optimize.

So I wrote a function:

function deleteShortMsg() {
  const msgDeleteElements = document.getElementsByClassName('byte-dropdown-item');
  if (msgDeleteElements.length > 0) {
    msgDeleteElements[0].click()
    setTimeout(() => {
      const confirmBtnElements = document.getElementsByClassName('btn-confirm')
      if (confirmBtnElements.length > 0) {
        confirmBtnElements[0].click()
      }
    }, 1000)
  }
}
// Invoke
setInterval(deleteShortMsg, 2000)

When I hit Enter, I sipped water and watched the short posts disappear one by one before my eyes.

Figure 6.gif

Afterwards

After a few more rounds of Mahjong Link, my short posts were as clean as my pockets…

Figure 7.png

Warning

In the end, I just want to say: Don't try it! Don't try it! Don't try it!

Summary

Of course, this isn't the first time I've done something like this.

One day before, I accidentally opened my own Qzone, scrolled through those unbearable texts, and had a similar idea.

So this was me transferring the experience over; the principle is pretty much the same.

I'll still briefly share my thought process and ideas here:

With that, a little life hack shared with everyone. I hope you never need to use it. Haha.

Comments

Top 1 from juejin.cn, machine-translated. The original thread is authoritative.

XCaptain

Good, not bad, write more