Twitch points

EZ money

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Twitch points
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  EZ money
// @author       rumpear
// @match        https://www.twitch.tv/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=twitch.tv
// @grant        none
// @license      MIT
// ==/UserScript==

const SECOND = 1000;
const MINUTE = 60 * SECOND;
const POINTS_PER_CLICK = 50;
const BONUS_BUTTON_SELECTOR = 'button[aria-label="Claim Bonus"]';
const GRAPE_HEX_COLOR = '#6F2DA8';
const HIBISCUS_HEX_COLOR = '#B43577';
const THISTLE_HEX_COLOR = '#D7BDFC';

let intervalTime = 15 * SECOND;
let intervalId = null;
let counter = 0;

const getCurrentTime = () => {
  return new Date();
};

const logMessageWithColor = (message = '', color = THISTLE_HEX_COLOR) => {
  console.log(`%c${message}`, `color: ${color}`);
};

const logPointsAmount = () => {
  const message = `you earned ${counter * POINTS_PER_CLICK} points: ${getCurrentTime()}`;
  logMessageWithColor(message, GRAPE_HEX_COLOR);
};

const handleBonusButtonClick = () => {
  const bonusButton = window.document.querySelector(BONUS_BUTTON_SELECTOR);

  if (bonusButton) {
    bonusButton.click();
    ++counter;
    logPointsAmount();
    clearInterval(intervalId);
    intervalTime = 15 * MINUTE;
    claimBonus();
  } else {
    const message = `button not found: ${getCurrentTime()}`;
    logMessageWithColor(message, HIBISCUS_HEX_COLOR);
  }
};

const claimBonus = () => {
  intervalId = setInterval(handleBonusButtonClick, intervalTime);
};

(function main() {
  logMessageWithColor('🫰TWITCH💰');
  claimBonus();
}());