DAILY DOCDAILY DOC
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
  • BFC 块级格式化上下文
  • Note
  • WebAssembly
  • public api
  • 位运算
  • bitwise operator
  • css实现隐藏效果
  • css snippets
  • 抖音点赞
  • js 相等判断
  • fetch ReadableStream
  • git
  • Github Actions 工作流
  • google search
  • RPC vs HTTP
  • gravatar
  • hhkb
  • Init project
  • input 文件上传
  • mac

    • Mac 使用技巧
    • alfred
    • mac shortcuts
    • shortcuts text edit
    • mac 修改host
  • 微前端
  • mock
  • nginx dump
  • nginx
  • NirCmd
  • npm
  • Operator Precedence
  • package.json
  • url query 解析
  • pnpm
  • JavaScript Precise countdown
  • react 模版
  • regexp
  • setup web development
  • telegram

    • telegram bot
  • timeFunction ease
  • 视频裁剪
  • vscode

    • vscode 高级指南
    • bracketPairs
    • jsconfig.json
    • vscode pipe into code
    • social project
    • vscode tasks
  • draggable resizable
  • windows 激活
  • 前端截图实现
  • 文本配音 富文本实现
  • 图片处理
  • 前端坐标
  • 定时任务
  • work efficient
  • 微信小程序动画实现方案
  • 排列组合
  • 数列
  • 语音驱动文字
  • 浏览器
  • 状态管理
  • 移动盒子
  • 移动端开发常用snippets
  • 设计模式
  • web performance

抖音点赞

web 脚本

Javascript
main();
async function main() {
    try {
        log('start');
        const run = createConcurrent(2);
        await waitFor(
            async () => {
                const target = [document.querySelector('#island_d3bbb'), document.querySelector('#island_d3bbb > div.LO5TGkc0')];

                await Promise.all(target.map(item => run(() => item.click())));
                log('click end ');
            },
            () => getRandomIntInclusive(1, 5) * 1e3
        );
        log('end');
    } catch (err) {
        console.error('err:', err);
    }
}

客户端模拟点击

Javascript
const robot = require('robotjs');

main();
async function main() {
  try {
    log('start');
    const run = createConcurrent(2);
    await waitFor(
      async () => {
        // 获取鼠标当前位置
        let mouse = robot.getMousePos();
        log('Mouse is at x:' + mouse.x + ' y:' + mouse.y);

        // 移动鼠标到指定位置 (例如:x = 500, y = 300)
        const x = 631 + getRandomIntInclusive(0, 60),
          y = 366 + getRandomIntInclusive(0, 50);
        robot.moveMouse(x, y);
        log('Mouse moved to', x, y);

        await Promise.all(
          new Array(getRandomIntInclusive(1, 30)).fill(0).map((item, index) =>
            run(async () => {
              // 执行鼠标左键点击
              robot.mouseClick();
              await delay(getRandomIntInclusive(1, 10) * 1e2);
              robot.moveMouse(
                x + getRandomIntInclusive(0, 50),
                y + getRandomIntInclusive(0, 50)
              );
              log('click', index);
            })
          )
        );

        // 将鼠标移回原位置
        log('click end ');
      },
      () => getRandomIntInclusive(1, 7) * 1e3
    );
    log('end');
  } catch (err) {
    console.error('err:', err);
  }
}
common libs

function getRandomIntInclusive(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
function log(...args) {
  return console.log(`[${new Date().toLocaleTimeString()}]: `, ...args);
}
async function waitFor(fn, msFn, maxCount = -1) {
  let pollCount = 0;

  async function callback(resolve, reject) {
    try {
      const res = await Promise.resolve(fn());
      if (res) {
        return resolve(res);
      }
    } catch (err) {
      log('fn poll err', fn?.name, err);
    }
    pollCount++;
    if (maxCount != -1 && pollCount > maxCount) {
      return reject(`maxCount limit, ${maxCount}`);
    }
    await delay(msFn());
    callback(resolve, reject);
  }

  await new Promise((resolve, reject) => callback(resolve, reject));
}

async function delay(ms) {
  return new Promise((resolve) => {
    const id = setTimeout(() => {
      clearTimeout(id);
      resolve(1);
    }, ms);
  });
}

function createConcurrent(concurrency) {
  let pendingCount = 0;
  const queue = [];

  async function concurrentWrapper(callback) {
    if (pendingCount >= concurrency) {
      await new Promise((resolve) => queue.push(resolve));
    }

    pendingCount++;
    try {
      await Promise.resolve(callback());
    } finally {
      pendingCount--;
      if (queue.length > 0) {
        const resolve = queue.shift();
        resolve();
      }
    }
  }
  return concurrentWrapper;
}


Last Updated:
Contributors: rosendo
Prev
css snippets
Next
js 相等判断