DailyIndieGame Tool

try to take over the world!

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

  1. // ==UserScript==
  2. // @name DailyIndieGame Tool
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.0
  5. // @description try to take over the world!
  6. // @icon http://www.dailyindiegame.com/dailyindiegame.png
  7. // @author Bisumaruko
  8. // @include http*://*dailyindiegame.com/account_digstore.html
  9. // @include http*://*dailyindiegame.com/account_trades.html
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var style = document.createElement('style');
  17.  
  18. style.type = 'text/css';
  19. style.innerHTML = `
  20. .DIGTool_checkbox {
  21. display: none;
  22. }
  23. .DIGTool_checked {
  24. background-color: #222; !important
  25. }
  26. `;
  27. document.head.appendChild(style);
  28.  
  29. var anchor = document.querySelector('#form3'),
  30. target = anchor.closest('tr').firstElementChild,
  31. DIGTool = document.createElement('div'),
  32. buttonSelectAll = document.createElement('button'),
  33. buttonPurchase = document.createElement('button');
  34.  
  35. buttonPurchase.textContent = 'Purchase';
  36. buttonPurchase.classList.add('DIG3_Orange_15_Form');
  37. buttonPurchase.addEventListener('click', async function () {
  38. let anchor = document.querySelector('a[href^="account_transac"]'),
  39. balance = parseInt(anchor.closest('div').textContent.slice(12)) || 0,
  40. list = Array.from(document.querySelectorAll('.DIGTool_checkbox:checked')),
  41. headers = new Headers(),
  42. bought = 0;
  43.  
  44. headers.append('Content-Type', 'application/x-www-form-urlencoded');
  45.  
  46. for (let item of list) {
  47. let id = parseInt(item.dataset.id),
  48. price = parseInt(item.dataset.price);
  49.  
  50. if (!id || !price || balance - price < 0) break;
  51.  
  52. let url = 'account_buy.html',
  53. init = {
  54. method: 'POST',
  55. headers: headers,
  56. body: 'quantity=1&xgameid=' + id + '&xgameprice1=' + price + '&send=Purchase',
  57. mode: 'same-origin',
  58. credentials: 'same-origin',
  59. cache: 'no-store',
  60. referrer: 'http://www.dailyindiegame.com/account_buy_' + id + '.html'
  61. };
  62.  
  63. if (location.href.includes('account_trades')) {
  64. url = 'account_buytrade_' + id + '.html';
  65. init.body = 'gameid=' + id + '&send=Purchase';
  66. init.referrer = 'http://www.dailyindiegame.com/account_buytrade_' + id + '.html';
  67. }
  68.  
  69. let res = await fetch(url, init);
  70.  
  71. if (res.ok) item.click();
  72. bought++;
  73. }
  74. if (bought) window.location = 'http://www.dailyindiegame.com/account_page.html';
  75. });
  76.  
  77. buttonSelectAll.textContent = 'Select All';
  78. buttonSelectAll.classList.add('DIG3_Orange_15_Form');
  79. buttonSelectAll.addEventListener('click', function () {
  80. let checkboxes = Array.from(document.querySelectorAll('.DIGTool_checkbox'));
  81.  
  82. for (let checkbox of checkboxes) {
  83. if (this.textContent == 'Select All') {
  84. if (!checkbox.checked) checkbox.click();
  85. } else {
  86. if (checkbox.checked) checkbox.click();
  87. }
  88. }
  89. this.textContent = this.textContent == 'Select All' ? 'Cancel' : 'Select All';
  90. });
  91.  
  92. DIGTool.appendChild(buttonPurchase);
  93. DIGTool.appendChild(buttonSelectAll);
  94.  
  95. while (target.lastChild) {
  96. target.removeChild(target.lastChild);
  97. }
  98.  
  99. target.appendChild(DIGTool);
  100.  
  101. var games = Array.from(document.querySelectorAll('a[href^="account_buy"]'));
  102.  
  103. for (let game of games) {
  104. let row = game.closest('tr'),
  105. checkbox = document.createElement('input');
  106.  
  107. checkbox.type = 'checkbox';
  108. checkbox.classList.add('DIGTool_checkbox');
  109. checkbox.dataset.id = game.href.replace(/\D/g,'');
  110. checkbox.dataset.price = parseInt(game.closest('td').previousElementSibling.textContent) || 0;
  111. checkbox.addEventListener('change', function () {
  112. let row = this.closest('tr');
  113.  
  114. if (this.checked) row.classList.add('DIGTool_checked');
  115. else row.classList.remove('DIGTool_checked');
  116. });
  117.  
  118. row.firstElementChild.appendChild(checkbox);
  119. row.addEventListener('click', function () {
  120. this.querySelector('input[type="checkbox"]').click();
  121. });
  122. }
  123. })();