Like Automator

This is a "like" automator (first N posts only).

当前为 2024-10-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Like Automator
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.6
  5. // @description This is a "like" automator (first N posts only).
  6. // @author biganthonymo
  7. // @match https://x.com/*/status/*
  8. // @icon data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTIyLjg4IDExNC40MiIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTIyLjg4IDExNC40MiIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj48IVtDREFUQVsKCS5zdDB7ZmlsbC1ydWxlOmV2ZW5vZGQ7Y2xpcC1ydWxlOmV2ZW5vZGQ7ZmlsbDojRUU0ODU2O30KCS5zdDF7ZmlsbC1ydWxlOmV2ZW5vZGQ7Y2xpcC1ydWxlOmV2ZW5vZGQ7ZmlsbDojRkZGRkZGO30KXV0+PC9zdHlsZT48Zz48cGF0aCBjbGFzcz0ic3QwIiBkPSJNOS4zMiwwaDEwNC4yNGM1LjEzLDAsOS4zMiw0LjIsOS4zMiw5LjMydjczLjYyYzAsNS4xMS00LjIxLDkuMzItOS4zMiw5LjMySDgzLjg0bC0xNi4xNywxOS4wNiBjLTMuNTgsNC4yMy05LjQ1LDQuMDQtMTIuODEsMEwzOS4wNCw5Mi4yNkg5LjMyQzQuMjEsOTIuMjYsMCw4OC4wNywwLDgyLjk0VjkuMzJDMCw0LjE5LDQuMTksMCw5LjMyLDBMOS4zMiwweiIvPjxwYXRoIGNsYXNzPSJzdDEiIGQ9Ik02MS4yLDMwLjQyYzMuNTMtMy42OCw2LTYuMTcsMTEuNDMtNi43OWMxMC4yLTEuMTcsMjAuMjcsOS4yNywxNS4xMiwxOS41NmMtMS45LDMuNzktOC40OSwxMC4xNi0xMy43NiwxNS4xNSBjLTIuMDEsMS45LTMuODMsMy42MS01LjEyLDQuODlsLTcuNjYsNy42bC02LjMzLTYuMDljLTEuOTEtMS44My00LjE2LTMuNzktNi40Ni01Ljg3QzQxLjUsNTIuNjQsMzQuMDUsNDUuMywzMy43NCwzNi43MyBjLTAuMjktOC4wMSw2LjcyLTEzLjE1LDE0LTEzLjA2QzU0LjIsMjMuNzYsNTYuOTIsMjYuMjUsNjEuMiwzMC40Mkw2MS4yLDMwLjQyeiIvPjwvZz48L3N2Zz4=
  9. // @grant none
  10. // @license MIT
  11.  
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to get random delay
  18. function getRandomDelay() {
  19. return Math.floor(Math.random() * 400) + 100; // Random delay between 100 and 500 ms
  20. }
  21.  
  22. function simulatePageDown() {
  23. // Scroll down by the height of the viewport
  24. window.scrollBy(0, window.innerHeight);
  25. }
  26.  
  27. function scrollDownMultipleTimes(times, delay) {
  28. for (let i = 0; i < times; i++) {
  29. setTimeout(function() {
  30. simulatePageDown();
  31. }, i * delay);
  32. }
  33. }
  34.  
  35. function simulatePageUp() {
  36. // Scroll up by the height of the viewport
  37. window.scrollBy(0, -window.innerHeight);
  38. }
  39.  
  40. function scrollUpMultipleTimes(times, delay) {
  41. for (let i = 0; i < times; i++) {
  42. setTimeout(function() {
  43. simulatePageUp();
  44. }, i * delay);
  45. }
  46. }
  47.  
  48. // Create the floating button
  49. const floatButton = document.createElement('button');
  50. floatButton.innerText = 'Like Automator';
  51. Object.assign(floatButton.style, {
  52. position: 'fixed',
  53. bottom: '20px',
  54. left: '20px',
  55. zIndex: '9999',
  56. padding: '10px',
  57. backgroundColor: '#007bff',
  58. color: '#fff',
  59. border: 'none',
  60. borderRadius: '5px',
  61. cursor: 'pointer'
  62. });
  63.  
  64. document.body.appendChild(floatButton);
  65.  
  66. floatButton.addEventListener('click', function() {
  67. const buttons = document.querySelectorAll('[data-testid="like"]');
  68. let clickedCount = 0;
  69. //scrollDownMultipleTimes(8, 500); //Scrool down a few times to load more elements
  70. //scrollUpMultipleTimes(8, 100);
  71.  
  72. function processButton(i) {
  73. if (i >= buttons.length || i >= 50) {
  74. return; // Stop if we've reached the end
  75. }
  76.  
  77. // Scroll to the button so it becomes visible
  78. buttons[i].scrollIntoView({
  79. behavior: 'smooth',
  80. block: 'center'
  81. });
  82.  
  83. // After scrolling, wait a bit before clicking
  84. setTimeout(function() {
  85. buttons[i].click();
  86. clickedCount++;
  87.  
  88. // Update the floating button's text to show how many clicks have happened so far
  89. floatButton.innerText = `Like Automator (${clickedCount} / ${buttons.length - 1})`; //The 1st does not count
  90.  
  91. // Process the next button after a random delay
  92. setTimeout(function() {
  93. processButton(i + 1);
  94. }, getRandomDelay());
  95. }, 500); // Wait 500ms after scrolling before clicking
  96. }
  97.  
  98. processButton(1); // Starting from 1 (the 2nd)
  99. });
  100. })();