Last active
May 26, 2019 20:19
-
-
Save TheOdd/f2169d1ebec2b34a9c664f0928082593 to your computer and use it in GitHub Desktop.
Allows for the user to easily enter and leave giveaways from the homepage of SteamGifts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SteamGifts Easy-Enter | |
// @homepage https://gist.github.com/TheOdd/f2169d1ebec2b34a9c664f0928082593/ | |
// @version 1.5.1 | |
// @description Allows for the user to easily enter and leave giveaways from the homepage of SteamGifts. | |
// @author TheOdd | |
// @match https://www.steamgifts.com/ | |
// @match https://www.steamgifts.com/giveaways/search?page=* | |
// @grant none | |
// @require http://code.jquery.com/jquery-latest.min.js | |
// @updateURL https://gist.githubusercontent.com/raw/f2169d1ebec2b34a9c664f0928082593/SteamGiftsEasyEnter.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const xsrf_token = $("[name='xsrf_token']").attr('value') | |
const giveawayCodeRegEx = /^\/(?:giveaway)\/(.+)\// | |
$('a.giveaway_image_thumbnail, a.giveaway_image_thumbnail_missing').each(function() { | |
const code = $(this).attr('href').match(giveawayCodeRegEx)[1] | |
$(this).attr('code', code) | |
$(this).removeAttr('href') | |
$(this).click(function() { | |
const pointsLeft = parseInt($('span.nav__points').text()) | |
const pointText = $(this).parent().children().first().children().first().children('span:last').text() | |
const cost = parseInt(pointText.substring(1, pointText.length - 2)) | |
const isFaded = $(this).parent().hasClass('is-faded') | |
if (pointsLeft >= cost || isFaded) { | |
$.ajax('https://www.steamgifts.com/ajax.php', { | |
method: 'POST', | |
data: { | |
code: $(this).attr('code'), | |
do: isFaded ? 'entry_delete' : 'entry_insert', | |
xsrf_token: xsrf_token | |
} | |
}) | |
$('span.nav__points').text((pointsLeft + (isFaded ? cost : -cost)).toString()) | |
$(this).parent().toggleClass('is-faded') | |
} | |
}) | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Any kind of user script browser extension. I use Tampermonkey.
Links:
Tampermonkey for Chrome
Tampermonkey for FireFox
Installation
Just click the Raw button at the top right of the file to directly view the file. This will open your script extension's installation page for the script.
Usage
Click on the giveaway thumbnails on the homepage of SteamGifts to toggle entering the giveaway (e.g. leaving the giveaway if you were entered and joining if you weren't and have enough points)
The script also updates your points at the top of the page and grays out giveaways after entering them.
It also won't let you enter giveaways that you don't have enough points for.
Demo