Greasy Fork

Greasy Fork is available in English.

Auto Claim Twitch drop(CN only)

Auto clicking "claim" near the chat really

目前为 2022-06-12 提交的版本。查看 最新版本

// ==UserScript==
// @name         Auto Claim Twitch drop(CN only)
// @version      0.4
// @description  Auto clicking "claim" near the chat really
// @author       eebssk1
// @match        https://www.twitch.tv/*
// @run-at       document-end
// @license      MPL
// @namespace    CN_only
// ==/UserScript==

function time() {
    const today = new Date();
    const date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    const time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    const dateTime = date+' '+time;
    return dateTime
}

function close() {
  let button = document.querySelector('button[aria-label="关闭"]');
  if(button != null)
    button.click();
}

function main() {
    let done = false;
    let button = document.querySelector('button[aria-label="领取奖励"]');
    let button2 = null;
    let oblist = document.querySelectorAll('div[data-a-target="tw-core-button-label-text"]');
    for(let a of oblist ){
      if(a.innerText === "领取")
         button2 = a.parentElement.parentElement;
    }
    if(button != null){
        button.click();
        console.log('Clicked at '+ time());
        done = true;
    }
    if(button2 != null){
        button2.click();
        console.log('Clicked at '+ time());
        done = true;
    }
   if(done){
        setTimeout(close,1000);
        setTimeout(function(){ location.reload(); }, 2000);
   }
}

function mainfr() {
    setTimeout(main,1000);
}

const observer = new MutationObserver(mainfr);
observer.observe(document.body, {childList: true, subtree: true});