Skip to content

Instantly share code, notes, and snippets.

@nakami
Last active June 28, 2022 14:53
Show Gist options
  • Save nakami/3ade53d6b0345163d5e91eda9febd767 to your computer and use it in GitHub Desktop.
Save nakami/3ade53d6b0345163d5e91eda9febd767 to your computer and use it in GitHub Desktop.
On Amazon Gaming, add a button below "Games free with Prime" to click all "Claim game" buttons (Does not click on external offerings)
// ==UserScript==
// @name Amazon Gaming "Claim All Games" button
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Adds a button below "Games free with Prime" to click all "Claim game" buttons; Does not click on external offerings
// @author nakami
// @match http*://gaming.amazon.com/*
// @icon https://d2u4zldaqlyj2w.cloudfront.net/02b601d4-a3ab-41e5-b8ab-1083f15f1c68/favicon.ico
// @grant none
// @run-at document-idle
// ==/UserScript==
/*
Support me by donating to my PayPal:
https://www.paypal.com/donate/?hosted_button_id=VNDER8T6AZ732
Thank you!
*/
(function() {
'use strict';
function claimAll() {
console.log('Claim All Games');
let claimBtns = document.querySelectorAll('[data-a-target="offer-section-FGWP_FULL"] button[data-a-target="FGWPOffer"]');
//let claimExternalBtns = document.querySelectorAll('[data-a-target="offer-section-FGWP_FULL"] button[data-a-target="ExternalOfferClaim"]');
console.log("found number of buttons:" + claimBtns.length);
for (var i = 0, len = claimBtns.length; i < len; i++) {
claimBtns[i].click();
}
};
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
sleep(2000).then(() => {
let title = Array.from(document.getElementsByClassName("offer-list__section-title")).at(-1);
let newBtn = document.createElement('button');
newBtn.setAttribute('class', 'tw-interactive tw-button tw-button--prime');
let newSpan = document.createElement('span');
newSpan.setAttribute('class', 'tw-button__text');
newBtn.appendChild(newSpan);
let newP = document.createElement('p');
newP.setAttribute('class', 'tw-amazon-ember-regular tw-font-size-6 tw-lg-font-size-6 tw-md-font-size-6 tw-sm-font-size-6 tw-xl-font-size-6 tw-xs-font-size-6 tw-xxl-font-size-6');
newBtn.onclick = claimAll;
newP.textContent = 'Claim All Games';
newSpan.appendChild(newP);
title.parentNode.insertBefore(newBtn, title.nextSibling);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment