Skip to content

Instantly share code, notes, and snippets.

@TheOdd
Last active May 26, 2019 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheOdd/f2169d1ebec2b34a9c664f0928082593 to your computer and use it in GitHub Desktop.
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.
// ==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')
}
})
})
})();
@TheOdd
Copy link
Author

TheOdd commented May 5, 2018

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

Demo Gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment