jnaskali / Auto-Claim Itch.io Bundles

// ==UserScript==
// @name        Auto-Claim Itch.io Bundles
// @author      jnaskali
// @copyright   2021, Juhani Naskali (www.naskali.fi)
// @license     MIT
// @version     1.3
// @namespace   https://www.naskali.fi
// @downloadURL https://openuserjs.org/install/jnaskali/Auto-Claim_Itch.io_Bundles.user.js
//
// @match       https://itch.io/bundle/download/*
// @grant       none
//
// @description Automatically clicks all claim links on itch.io bundle download pages. Especially useful to automatically claim the ~thousand games in Itch.io Bundle for Racial Justice and Equality, Bundle for Ukraine, etc. Thanks to FlaminSarge for the javascript post code!
// ==/UserScript==

var $ = window.jQuery;

var clicked = 0;
var csrfToken = $('input[name="csrf_token"]')[0].value;


$('input[name="game_id"]').each(function() {
  setTimeout(function() {
      var gameId = $(this).val();
      $.post(window.location.href, { action: 'claim', csrf_token: csrfToken, game_id: gameId });
  }.bind(this), 500*clicked);
  
  clicked++;
});


if(clicked != 0) {
  var claimtext = document.createElement('div');
  claimtext.style.background = 'red';
  claimtext.style.color = 'white';
  claimtext.style.padding = '10px 0';
  claimtext.innerHTML = '<p>Please wait. Running Auto-Claim on ' + clicked + ' items...</p>';
  document.querySelector('.tabbed_header_widget').appendChild(claimtext);

  setTimeout(function() {
    claimtext.innerHTML = '<p>Done! Autoclaimed ' + clicked + ' items.</p>';
    claimtext.style.background = 'green';
  }.bind(this), 500*clicked+1000);
}


console.log("Auto-claimed " + clicked + " items.");