Auto Loot

自动领取每日奖励

נכון ליום 14-01-2021. ראה הגרסה האחרונה.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Auto Loot
// @namespace    https://blog.chrxw.com
// @version      0.3
// @description  自动领取每日奖励
// @author       Chr_
// @include      https://www.lootlink.me/*
// @grant        none
// ==/UserScript==

(function () {
    showLabel();
    dailyClaim();
})();


// 显示标签
function showLabel() {
    let uname = document.querySelector('#profileMenuInvoker>span');
    let tag = document.createElement('span');
    tag.textContent = ' (By Chr_) ';
    tag.addEventListener('click',()=>{
        window.open('https://blog.chrxw.com');
    });
    uname.appendChild(tag);
}

// 每日签到&自动开箱
function dailyClaim() {
    const MAX = 50;
    let tries = 0;
    clickDaily();
    retry(clickBox, 3000);
    function clickDaily() {
        let coin = document.querySelector('#wallet2 a[data-modal-target="#crate-modal"]');
        if (coin) {
            coin.click();
            retry(claimCoin, 1000);
        } else {
            retry(clickDaily, 500);
        }
    }    
    function clickBox() {
        let coin = document.querySelector('#wallet2 [src="/images/art/crate.png"]:not(.grayscale)');
        if (coin) {
            coin.click();
            retry(claimCoin, 1000);
        }  else {
            retry(clickBox, 500);
        }
    }
    function claimCoin() {
        let claimbtn = document.querySelector("#cratetab > a");
        if (claimbtn) {
            claimbtn.click();
            tries = 0;
            retry(closePanel, 1500);
        } else {
            retry(claimCoin, 500);
        }
    }
    function closePanel() {
        let title = document.querySelector("#cratetab > h4");
        if (title.textContent.search('Opened') != -1 || title.textContent.search('Received') != -1) {
            let closebtn = document.querySelector("#crate-modal > button");
            closebtn.click();
        } else {
            retry(closePanel, 500);
        }
    }

    function retry(foo, t) {
        console.log(foo.name);
        if (tries++ <= MAX) {
            setTimeout(() => {
                try {
                    foo();
                }
                catch (e) {
                    console.log(e);
                    throw e;
                }
            }, t);
        } else {
            log('操作超时');
        }
    }
}