QQ空间自动删除互动记录

自动删除“与我相关(点赞记录、评论)”

当前为 2019-08-10 提交的版本,查看 最新版本

// ==UserScript==
// @name         QQ空间自动删除互动记录
// @description  自动删除“与我相关(点赞记录、评论)”
// @namespace    https://greasyfork.org/users/197529
// @homepage     https://greasyfork.org/scripts/388383
// @supportURL   https://greasyfork.org/scripts/388383/feedback
// @version      0.1
// @author       kkocdko
// @license      Unlicense
// @match        *://user.qzone.qq.com/*
// @noframes
// ==/UserScript==
'use strict'

const addFloatButton = initFloatButton()

addFloatButton('删除所有与我相关', async function () {
  this.loop = !this.loop
  const refreshButtonEl = document.querySelector('#feed_me_refresh')
  window.alert('需将鼠标指针移到项目卡片右上角的箭头上')
  document.querySelector('#tab_menu_me').click()
  while (this.loop) {
    refreshButtonEl.click()
    try {
      await waitUntilAsync(() => document.querySelectorAll('.f-single').length > 2)
    } catch (e) {
      continue
    }
    await sleepAsync(500)
    for (let i = 0; i < 4; i++) {
      for (let j = 0; j < 4; j++) {
        try {
          document.querySelector('.qz_fop_delete').click()
          await sleepAsync(70)
          document.querySelector('.ui-popup-focus .qz-dark-button').click()
          await sleepAsync(1100)
        } catch (e) { }
      }
      window.scrollTo(0, document.documentElement.scrollHeight || document.body.scrollHeight)
      await sleepAsync(100)
      window.scrollTo(0, 0)
      await sleepAsync(500)
    }
  }
})

async function sleepAsync (time) {
  return new Promise(resolve => setTimeout(resolve, time))
}

async function waitUntilAsync (conditionCalculator, timeout = 9000, interval = 200) {
  const startTime = Date.now()
  return new Promise((resolve, reject) => {
    setInterval(() => {
      if (conditionCalculator()) {
        resolve()
      } else if (Date.now() - startTime > timeout) {
        reject(new Error())
      }
    }, interval)
  })
}

function initFloatButton () {
  return (document.addFloatButton = document.addFloatButton || (() => {
    const buttonBarShadow = document.createElement('div').attachShadow({ mode: 'open' })
    buttonBarShadow.innerHTML = '<style>:host{position:fixed;top:3px;left:3px;z-index:9999999999;height:0}input{display:none}input~*{float:left;margin:3px;padding:1em;outline:0;border:0;border-radius:4px;background:#2196f3;box-shadow:0 1px 3px 0 #00000022;color:#fff;font-size:14px;line-height:0;transition:.3s}:active{background:#63b5f7;box-shadow:0 2px 5px 0 #00000033}label{border-radius:50%}input:checked~label{opacity:.3;transform:translateY(3em)}button:active{transition:0s}input:checked~button{visibility:hidden;opacity:0;transform:translateY(-3em)}</style><input id=hidebtns type=checkbox><label for=hidebtns></label>'
    document.body.appendChild(buttonBarShadow.host)
    return (text, onclick) => {
      const button = document.createElement('button')
      button.textContent = text
      button.addEventListener('click', onclick)
      return buttonBarShadow.appendChild(button)
    }
  })())
}