Auto Loot

自动领取每日奖励

Stan na 14-01-2021. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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('操作超时');
        }
    }
}