Greasy Fork

Greasy Fork is available in English.

DailyIndieGame Tool

try to take over the world!

当前为 2017-04-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         DailyIndieGame Tool
// @namespace    http://tampermonkey.net/
// @version      1.1.0
// @description  try to take over the world!
// @icon         http://www.dailyindiegame.com/dailyindiegame.png
// @author       Bisumaruko
// @include      http*://*dailyindiegame.com/account_digstore.html
// @include      http*://*dailyindiegame.com/account_trades.html
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var style = document.createElement('style');

    style.type = 'text/css';
    style.innerHTML = `
        .DIGTool_checkbox {
            display: none;
        }
        .DIGTool_checked {
            background-color: #222; !important
        }
    `;
    document.head.appendChild(style);

    var anchor = document.querySelector('#form3'),
        target = anchor.closest('tr').firstElementChild,
        DIGTool = document.createElement('div'),
        buttonSelectAll = document.createElement('button'),
        buttonPurchase = document.createElement('button');

    buttonPurchase.textContent = 'Purchase';
    buttonPurchase.classList.add('DIG3_Orange_15_Form');
    buttonPurchase.addEventListener('click', async function () {
        let anchor = document.querySelector('a[href^="account_transac"]'),
            balance = parseInt(anchor.closest('div').textContent.slice(12)) || 0,
            list = Array.from(document.querySelectorAll('.DIGTool_checkbox:checked')),
            headers = new Headers(),
            bought = 0;

        headers.append('Content-Type', 'application/x-www-form-urlencoded');

        for (let item of list) {
            let id = parseInt(item.dataset.id),
                price = parseInt(item.dataset.price);

            if (!id || !price || balance - price < 0) break;

            let url = 'account_buy.html',
                init = {
                    method: 'POST',
                    headers: headers,
                    body: 'quantity=1&xgameid=' + id + '&xgameprice1=' + price + '&send=Purchase',
                    mode: 'same-origin',
                    credentials: 'same-origin',
                    cache: 'no-store',
                    referrer: 'http://www.dailyindiegame.com/account_buy_' + id + '.html'
                };

            if (location.href.includes('account_trades')) {
                url = 'account_buytrade_' + id + '.html';
                init.body = 'gameid=' + id + '&send=Purchase';
                init.referrer = 'http://www.dailyindiegame.com/account_buytrade_' + id + '.html';
            }

            let res = await fetch(url, init);

            if (res.ok) item.click();
            bought++;
        }
        if (bought) window.location = 'http://www.dailyindiegame.com/account_page.html';
    });

    buttonSelectAll.textContent = 'Select All';
    buttonSelectAll.classList.add('DIG3_Orange_15_Form');
    buttonSelectAll.addEventListener('click', function () {
        let checkboxes = Array.from(document.querySelectorAll('.DIGTool_checkbox'));

        for (let checkbox of checkboxes) {
            if (this.textContent == 'Select All') {
                if (!checkbox.checked) checkbox.click();
            } else {
                if (checkbox.checked) checkbox.click();
            }
        }
        this.textContent = this.textContent == 'Select All' ? 'Cancel' : 'Select All';
    });

    DIGTool.appendChild(buttonPurchase);
    DIGTool.appendChild(buttonSelectAll);

    while (target.lastChild) {
        target.removeChild(target.lastChild);
    }

    target.appendChild(DIGTool);

    var games = Array.from(document.querySelectorAll('a[href^="account_buy"]'));

    for (let game of games) {
        let row = game.closest('tr'),
            checkbox = document.createElement('input');

        checkbox.type = 'checkbox';
        checkbox.classList.add('DIGTool_checkbox');
        checkbox.dataset.id = game.href.replace(/\D/g,'');
        checkbox.dataset.price = parseInt(game.closest('td').previousElementSibling.textContent) || 0;
        checkbox.addEventListener('change', function () {
            let row = this.closest('tr');

            if (this.checked) row.classList.add('DIGTool_checked');
            else row.classList.remove('DIGTool_checked');
        });

        row.firstElementChild.appendChild(checkbox);
        row.addEventListener('click', function () {
            this.querySelector('input[type="checkbox"]').click();
        });
    }
})();