List liker

try to take over the world!

目前為 2021-06-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name         List liker
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  try to take over the world!
// @author       You
// @match        https://twitter.com/i/lists/1390432068866281476
// @icon         https://www.google.com/s2/favicons?domain=twitter.com
// @grant        none
// ==/UserScript==

(function () {
  setTimeout(() => {
    'use strict';

    const fireEvent = (el, etype) => {
      var evObj = document.createEvent('Events');
      evObj.initEvent(etype, true, false);
      el.dispatchEvent(evObj);
    }
    const random = (min, max) => Math.random() * (max - min) + min;
    const getHearts = () => Array.from(document.querySelectorAll('[d="M12 21.638h-.014C9.403 21.59 1.95 14.856 1.95 8.478c0-3.064 2.525-5.754 5.403-5.754 2.29 0 3.83 1.58 4.646 2.73.814-1.148 2.354-2.73 4.645-2.73 2.88 0 5.404 2.69 5.404 5.755 0 6.376-7.454 13.11-10.037 13.157H12zM7.354 4.225c-2.08 0-3.903 1.988-3.903 4.255 0 5.74 7.034 11.596 8.55 11.658 1.518-.062 8.55-5.917 8.55-11.658 0-2.267-1.823-4.255-3.903-4.255-2.528 0-3.94 2.936-3.952 2.965-.23.562-1.156.562-1.387 0-.014-.03-1.425-2.965-3.954-2.965z"]'))
    const getTweets = (current) => {
      const all = Array.from(document.querySelectorAll('article'));
      return all.slice(all.indexOf(current) + 1);
    }

    let tweets = [];
    let currentIndex = 0;
    let reloads = 0;
    let maxReloads = 10;
    let blurTime = 0;
    let blurTimeout = 60000 * 2; // 2 minutes tab blurred, reload on focus

    // Handle blur/focus to reload page when returning (prevents weird scrolling behavior)
    window.addEventListener('blur', () => (blurTime = Date.now()));
    window.addEventListener('focus', () => (Date.now() - blurTime > blurTimeout && window.location.reload()));

    // Start the infinite loop
    setInterval(() => {
      if (reloads > maxReloads) {
        window.location.reload();
      }

      let tweet = tweets[currentIndex++];
      if (!tweet) {
        tweets = getTweets(tweets[currentIndex - 2]);
        currentIndex = 0;
        tweet = tweets[currentIndex++];
        reloads++;
        console.log('RELOAD', reloads)
      }

      getHearts().forEach((h) => setTimeout(() => fireEvent(h, 'click'), random(300, 3300)));

      tweet.scrollIntoView({ behavior: 'smooth', block: 'center' })
    }, 6000);
  }, 3000)
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址