Improved token handling, CSRF expiry check

This commit is contained in:
Abhorrent_Anger 2026-08-19 18:30:25 +03:00
parent f424787db7
commit 3fd55c5214

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @name Mann Co. Store Giveaway Autojoiner // @name Mann Co. Store Giveaway Autojoiner
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 2026-08-21 // @version 2026-08-22
// @description Tries to join giveaways on page load // @description Tries to join giveaways on page load
// @author Abhorrent_Anger // @author Abhorrent_Anger
// @include /^https?:\/\/mannco\.store\/giveaways.?$/ // @include /^https?:\/\/mannco\.store\/giveaways.*?/
// @icon https://www.google.com/s2/favicons?sz=64&domain=mannco.store // @icon https://www.google.com/s2/favicons?sz=64&domain=mannco.store
// @grant GM_xmlhttpRequest // @grant GM_xmlhttpRequest
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
@ -15,22 +15,34 @@
setTimeout(function () { location.reload(); }, 90 * 60 * 1000); setTimeout(function () { location.reload(); }, 90 * 60 * 1000);
const OPEN_GIVEAWAY_SELECTOR = '.giveaways-list-item:not(.giveaways-list-item--joined)'; const OPEN_GIVEAWAY_SELECTOR = '.giveaways-list-item:not(.giveaways-list-item--joined)';
const NUXT_DATA_SELETOR = '#__NUXT_DATA__';
var bearerToken = '';
var csrfToken = '';
waitForKeyElements('.giveaways__content', () => { waitForKeyElements('.giveaways__content', () => {
if ($(OPEN_GIVEAWAY_SELECTOR).len == 0) { if ($(OPEN_GIVEAWAY_SELECTOR).len == 0) {
return true; return true;
} }
updateTokensandJoin(); if (updateTokens() && bearerToken && csrfToken) {
joinGiveaways(bearerToken, csrfToken);
} else {
console.log('Couldn\'t fetch tokens for joining the giveaways!');
}
console.log('Done with giveaway join attempts'); console.log('Done with giveaway join attempts');
}); });
function updateTokensandJoin() { function updateTokens() {
var bearerToken = getTokenFromCookie('auth'); bearerToken = getTokenFromCookie('auth');
var csrfToken = getTokenFromCookie('csrf'); if (bearerToken) {
console.log('Fetched the Bearer token from cookies: ', bearerToken);
} else {
console.log('Couldn\'t fetch the Bearer token from cookies: ', bearerToken);
return false;
}
csrfToken = getTokenFromCookie('csrf');
if (csrfToken) { if (csrfToken) {
console.log('Fetched the CSRF token from cookies: ', csrfToken) console.log('Fetched the CSRF token from cookies: ', csrfToken)
joinGiveaways(bearerToken, csrfToken);
return true; return true;
} }
let xCSRF = new GM_xmlhttpRequest({ let xCSRF = new GM_xmlhttpRequest({
@ -42,20 +54,25 @@ function updateTokensandJoin() {
if (response.status == 200) { if (response.status == 200) {
let array = JSON.parse(response.response); let array = JSON.parse(response.response);
csrfToken = array['content']['csrf_token']; csrfToken = array['content']['csrf_token'];
console.log('Successfully updated the CSRF token: ', csrfToken) console.log('Successfully updated the CSRF token from API: ', csrfToken)
joinGiveaways(bearerToken, csrfToken); return true;
} else { } else {
console.log('Couldn\'t get a CSRF token!') console.log('Couldn\'t get a CSRF token!')
} }
} }
} }
}); });
return false;
} }
function joinGiveaways(bearerToken, csrfToken) { function joinGiveaways(bearerToken, csrfToken) {
$(OPEN_GIVEAWAY_SELECTOR).each(function () { $(OPEN_GIVEAWAY_SELECTOR).each(function () {
let giveawayURL = $(this).attr('href'); let giveawayURL = $(this).attr('href');
let giveaway = /[^/]*$/.exec(giveawayURL)[0]; let giveaway = /[^/]*$/.exec(giveawayURL)[0];
if (!giveaway || giveaway == 'undefined') {
console.log('Couldn\'t detect the giveaway ID!', $(this), giveawayURL, giveaway);
return;
}
let giveawayJoinURL = 'https://api.mannco.store/giveaways/join/' + giveaway; let giveawayJoinURL = 'https://api.mannco.store/giveaways/join/' + giveaway;
let xJoin = new GM_xmlhttpRequest({ let xJoin = new GM_xmlhttpRequest({
method: 'POST', method: 'POST',
@ -84,9 +101,12 @@ function getTokenFromCookie(tokenName) {
let cookieArray = getCookie(tokenName); let cookieArray = getCookie(tokenName);
let decodedTokenArray = decodeURIComponent(cookieArray); let decodedTokenArray = decodeURIComponent(cookieArray);
if (typeof decodedTokenArray !== 'string' || !decodedTokenArray) { if (typeof decodedTokenArray !== 'string' || !decodedTokenArray || decodedTokenArray == undefined) {
return false; return false;
} }
let array = JSON.parse(decodedTokenArray, true); let array = JSON.parse(decodedTokenArray, true);
if (array['expiresAt'] === undefined || array['expiresAt'] > Date.now()) {
return array['token']; return array['token'];
} }
return false;
}