Warning: fopen(/www/sites/update.greasyfork.icu/index/store/forever/ad33a2f315ced5bf67f33c719df15b3e.js): failed to open stream: No space left on device in /www/sites/update.greasyfork.icu/index/scriptControl.php on line 65
// ==UserScript==
// @name DailyIndieGame Tool
// @namespace http://tampermonkey.net/
// @version 1.3.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
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
var $ = selector => document.querySelector(selector),
$$ = selector => Array.from(document.querySelectorAll(selector));
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 target = $('#form3').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', function () {
let list = $$('.DIGTool_checkbox:checked'),
queue = [],
headers = new Headers(),
bought = 0,
balance = parseInt($('a[href^="account_transac"]').closest('div').textContent.slice(12)) || 0,
sequence = function (current) {
if (current) {
if (balance - current.price < 0) {
msg.alert('Not enough DIG points');
return;
}
fetch(current.req)
.then(res => {
if (res.ok) {
current.dom.click();
bought++;
balance -= current.price;
sequence(queue.shift());
} else msg.alert('Purchase failed, server responded an error');
});
} else {
if (bought) window.location = 'http://www.dailyindiegame.com/account_page.html';
}
};
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 || isNaN(price)) continue;
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';
}
queue.push({
req: new Request(url, init),
price: price,
dom: item
});
}
sequence(queue.shift());
});
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();
});
}
var msg = {
box: null,
init() {
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = `
.DIGTool_msg {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 10px 20px;
border: 1px solid #424242;
background-color: rgb(32, 32, 32);
color: #FFF;
font-size: larger;
}
.DIGTool_msg-show {
display: block;
}
`;
document.head.appendChild(style);
var DIGTool_msg = document.createElement('div');
DIGTool_msg.classList.add('DIGTool_msg');
document.body.appendChild(DIGTool_msg);
this.box = DIGTool_msg;
},
alert(text) {
this.box.textContent = text;
this.box.classList.add('DIGTool_msg-show');
setTimeout(this.hide.bind(this), 3000);
},
hide() {
this.box.classList.remove('DIGTool_msg-show');
}
};
msg.init();
})();