抖音视频播放量刷取-按键模式定制

抖音视频播放量刷取,支持按键模式自定义,并显示执行次数-有封号风险,请谨慎使用,该脚本只用于学习用途,请勿用于违法行为。

  1. // ==UserScript==
  2. // @name 抖音视频播放量刷取-按键模式定制
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description 抖音视频播放量刷取,支持按键模式自定义,并显示执行次数-有封号风险,请谨慎使用,该脚本只用于学习用途,请勿用于违法行为。
  6. // @author Sweek
  7. // @license GPLv3
  8. // @match *://www.douyin.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. // 模拟按下键盘的函数
  13. function pressKey(keyCode) {
  14. const event = new KeyboardEvent('keydown', { keyCode });
  15. document.dispatchEvent(event);
  16. }
  17.  
  18. // 定义“上”和“下”键的 keyCode
  19. const KEY_UP = 38; // 上箭头键的 keyCode
  20. const KEY_DOWN = 40; // 下箭头键的 keyCode
  21.  
  22. // 生成一个 1 到 5 秒之间的随机间隔(单位:毫秒)
  23. function getRandomInterval() {
  24. return Math.floor(Math.random() * 4000) + 1000; // 返回一个 1000 到 5000 毫秒之间的随机数
  25. }
  26.  
  27. // 按键交替执行的函数,按模式执行(例如:4次下键、4次上键等)
  28. function pressKeysByPattern(pattern, timesPerAction, repeatCount, updateProgress) {
  29. return new Promise((resolve) => {
  30. let count = 0;
  31. let patternIndex = 0;
  32. let repeatIndex = 0; // 控制模式循环次数
  33. // 循环执行按键操作
  34. function pressNextKey() {
  35. if (repeatIndex < repeatCount) { // 如果还需要重复
  36. if (count < pattern.length * timesPerAction) {
  37. // 根据模式按键
  38. const currentKey = pattern[patternIndex];
  39. const keyToPress = (currentKey === 'down') ? KEY_DOWN : KEY_UP;
  40. pressKey(keyToPress);
  41. count++;
  42. // 每按一次键后等待随机间隔时间,然后继续执行
  43. const interval = getRandomInterval();
  44. // 每按完一轮后检查是否切换到下一个模式
  45. if (count % timesPerAction === 0) {
  46. patternIndex++;
  47. if (patternIndex >= pattern.length) {
  48. patternIndex = 0; // 重置模式索引,循环执行
  49. }
  50. }
  51. setTimeout(pressNextKey, interval);
  52. } else {
  53. // 完成一次模式后,重置计数器,准备开始下一轮
  54. count = 0;
  55. repeatIndex++; // 增加重复次数
  56. updateProgress(repeatIndex, repeatCount); // 更新显示的循环进度
  57. setTimeout(pressNextKey, getRandomInterval()); // 等待一段时间后开始下一轮
  58. }
  59. } else {
  60. resolve(); // 完成所有任务
  61. }
  62. }
  63. pressNextKey(); // 开始按键操作
  64. });
  65. }
  66.  
  67. // 在页面右上角添加一个显示进度的框
  68. function createProgressBox() {
  69. const box = document.createElement('div');
  70. box.style.position = 'fixed';
  71. box.style.top = '10px';
  72. box.style.right = '10px';
  73. box.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
  74. box.style.color = '#fff';
  75. box.style.padding = '10px';
  76. box.style.borderRadius = '5px';
  77. box.style.fontSize = '16px';
  78. box.style.zIndex = '9999';
  79. const title = document.createElement('div');
  80. title.textContent = '执行进度:';
  81. box.appendChild(title);
  82. const countDisplay = document.createElement('div');
  83. countDisplay.id = 'executionCount';
  84. countDisplay.textContent = '已执行: 0 / 0'; // 默认初始值为 0 / 0
  85. box.appendChild(countDisplay);
  86. document.body.appendChild(box);
  87. }
  88.  
  89. // 更新显示的执行进度
  90. function updateProgressDisplay(repeatIndex, repeatCount) {
  91. const countDisplay = document.getElementById('executionCount');
  92. if (countDisplay) {
  93. countDisplay.textContent = `已执行: ${repeatIndex} / ${repeatCount}`;
  94. }
  95. }
  96.  
  97. // 执行脚本,传入需要的按键模式和每个动作的次数
  98. (async function () {
  99. const repeatCount = 10; // 设置总的循环次数
  100. createProgressBox(); // 创建进度显示框
  101. // 在开始之前,初始化进度框的显示
  102. updateProgressDisplay(0, repeatCount); // 初始化为 0 / repeatCount
  103. const pattern = ['down', 'up']; // 按下‘下’键4次,再按上‘上’键4次
  104. const timesPerAction = 4; // 每个动作的次数:4次下键或上键
  105.  
  106. // 执行多次按键循环
  107. await pressKeysByPattern(pattern, timesPerAction, repeatCount, updateProgressDisplay);
  108. })();