Last active
November 5, 2023 16:36
-
-
Save sergiosusa/eec3bd89a7b786541c3ebe24e7cbda12 to your computer and use it in GitHub Desktop.
User script to auto-join all giveaways from indiegala.com.
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 AutoJoin IndieGala Giveaways | |
// @namespace http://sergiosusa.com | |
// @version 0.13 | |
// @description Autojoin for IndieGala Giveaways! | |
// @author Sergio Susa (http://sergiosusa.com) | |
// @match https://www.indiegala.com/giveaways* | |
// @grant none | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js | |
// ==/UserScript== | |
/******* Global Variables *******/ | |
var reloading = 600000; | |
var nextPageTime = 40000; | |
var minCoins = 5; | |
var minLevel = 3; | |
/******* Script Variables *******/ | |
var index = 0; | |
var giveawayButtons; | |
var intervalId; | |
var totalCoins = 0; | |
/*******************************/ | |
(function () { | |
'use strict'; | |
$.noConflict(); | |
jQuery('document').ready(function () { | |
if (window.location.href === 'https://www.indiegala.com/giveaways') { | |
insertGraphicElements(); | |
} | |
setTimeout(function () { | |
removeExtraOdds(); | |
totalCoins = getTotalCoinsAvailable(); | |
if (totalCoins < minCoins) { | |
reloadPage(reloading); | |
return; | |
} | |
if (window.location.href.indexOf('/expiry/asc') !== -1) { | |
giveawayButtons = jQuery('aside.animated-coupon'); | |
if (giveawayButtons.length > 0) { | |
intervalId = setInterval(function () { | |
giveawayButtons[index].click(); | |
index++; | |
if (index >= giveawayButtons.length) { | |
clearInterval(intervalId); | |
index = 0; | |
} | |
}, 2000); | |
} | |
setTimeout(function () { | |
var page = calculateNextPage(); | |
redirectToPage(page); | |
}, nextPageTime); | |
} | |
},2000); | |
}); | |
})(); | |
/*********************************************************** | |
* Utility Functions | |
**********************************************************/ | |
function insertGraphicElements() { | |
var buttonContainer = jQuery("div.cover-text")[0]; | |
var anchor = document.createElement('a'); | |
anchor.innerHTML = 'Join Giveaways'; | |
anchor.href = '#'; | |
anchor.className = 'palette-background-1 palette-color-6'; | |
anchor.onclick = startJoin; | |
buttonContainer.prepend(anchor); | |
} | |
function removeExtraOdds() | |
{ | |
var type = jQuery(".extra-type"); | |
var element = type.splice(1,1); | |
while( 0 !== element.length){ | |
if (element[0].innerHTML.trim()!='single ticket'){ | |
element[0].parentNode.parentNode.parentNode.parentNode.parentNode.remove(); | |
} | |
element = type.splice(1,1); | |
} | |
} | |
function getTotalCoinsAvailable() { | |
jQuery('div.account-galamoney img:last-child')[1].remove(); | |
return $('div.account-galamoney')[2].innerText.replace('GalaSilver', '').trim(); | |
} | |
function startJoin() { | |
localStorage.setItem("actualLevel", minLevel); | |
redirectToPage(1); | |
} | |
function redirectToPage(page) { | |
window.location = 'https://www.indiegala.com/giveaways/[NUM_PAGE]/expiry/asc/level/[MIN_LEVEL]'.replace('[NUM_PAGE]', page).replace('[MIN_LEVEL]', localStorage.getItem("actualLevel")); | |
} | |
function calculateNextPage() { | |
var page = window.location.href.replace('https://www.indiegala.com/giveaways/', '').replace('/expiry/asc/level/' + localStorage.getItem("actualLevel"), ''); | |
page = parseInt(page) + 1; | |
if (page > calculateLastPage()) { | |
var newLevel = localStorage.getItem("actualLevel"); | |
newLevel = newLevel - 1; | |
if (newLevel < 0) { | |
newLevel = minLevel; | |
} | |
localStorage.setItem("actualLevel", newLevel ); | |
page = 1; | |
} | |
return page; | |
} | |
function calculateLastPage() { | |
var lastPage = 1; | |
if(jQuery("div.page-nav div.page-link-cont:last-child a")[0] !== undefined) { | |
lastPage = parseInt(jQuery("div.page-nav div.page-link-cont:last-child a")[0].href.replace('https://www.indiegala.com/giveaways/', '').replace('/expiry/asc/level/' + localStorage.getItem("actualLevel"), '')); | |
} | |
return lastPage; | |
} | |
function reloadPage(milliseconds) { | |
setInterval(function () { | |
window.location.reload(); | |
}, milliseconds); | |
} | |
/*********************************************************** | |
* Override Functions | |
**********************************************************/ | |
window.confirm = function (message, callback, caption) { | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment