CSRF fetching if needed
This commit is contained in:
parent
325d01d014
commit
f424787db7
@ -1,7 +1,7 @@
|
|||||||
// ==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-20
|
// @version 2026-08-21
|
||||||
// @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.?$/
|
||||||
@ -14,46 +14,79 @@
|
|||||||
|
|
||||||
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)';
|
||||||
|
|
||||||
waitForKeyElements('.giveaways__content', () => {
|
waitForKeyElements('.giveaways__content', () => {
|
||||||
setTimeout(function () {
|
if ($(OPEN_GIVEAWAY_SELECTOR).len == 0) {
|
||||||
$('.giveaways-list-item:not(.giveaways-list-item--joined)').each(function () {
|
return true;
|
||||||
|
}
|
||||||
|
updateTokensandJoin();
|
||||||
|
|
||||||
|
console.log('Done with giveaway join attempts');
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateTokensandJoin() {
|
||||||
|
var bearerToken = getTokenFromCookie('auth');
|
||||||
|
var csrfToken = getTokenFromCookie('csrf');
|
||||||
|
if (csrfToken) {
|
||||||
|
console.log('Fetched the CSRF token from cookies: ', csrfToken)
|
||||||
|
joinGiveaways(bearerToken, csrfToken);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
let xCSRF = new GM_xmlhttpRequest({
|
||||||
|
method: 'GET',
|
||||||
|
url: 'https://api.mannco.store/csrf/token',
|
||||||
|
headers: { 'Authorization': 'Bearer ' + bearerToken },
|
||||||
|
onreadystatechange: function (response) {
|
||||||
|
if (response.readyState == 4) {
|
||||||
|
if (response.status == 200) {
|
||||||
|
let array = JSON.parse(response.response);
|
||||||
|
csrfToken = array['content']['csrf_token'];
|
||||||
|
console.log('Successfully updated the CSRF token: ', csrfToken)
|
||||||
|
joinGiveaways(bearerToken, csrfToken);
|
||||||
|
} else {
|
||||||
|
console.log('Couldn\'t get a CSRF token!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function joinGiveaways(bearerToken, csrfToken) {
|
||||||
|
$(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];
|
||||||
let giveawayJoinURL = 'https://api.mannco.store/giveaways/join/' + giveaway;
|
let giveawayJoinURL = 'https://api.mannco.store/giveaways/join/' + giveaway;
|
||||||
|
|
||||||
let bearerToken = getTokenFromCookie('auth');
|
|
||||||
let csrfToken = getTokenFromCookie('csrf');
|
|
||||||
|
|
||||||
let xJoin = new GM_xmlhttpRequest({
|
let xJoin = new GM_xmlhttpRequest({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: giveawayJoinURL,
|
url: giveawayJoinURL,
|
||||||
headers: { 'Authorization': 'Bearer ' + bearerToken, 'X-Csrf-Token': csrfToken },
|
headers: { 'Authorization': 'Bearer ' + bearerToken, 'X-Csrf-Token': csrfToken },
|
||||||
onreadystatechange: function (response) {
|
onreadystatechange: function (response) {
|
||||||
if (response.readyState == 4 && response.status == 200) {
|
if (response.readyState == 4) {
|
||||||
|
if (response.status == 200) {
|
||||||
console.log('Successfully joined ' + giveaway, response.response);
|
console.log('Successfully joined ' + giveaway, response.response);
|
||||||
} else {
|
} else {
|
||||||
console.log("Couldn't join " + giveaway, response);
|
console.log("Couldn't join " + giveaway, response, bearerToken, csrfToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.log('Done with giveaway join attempts');
|
}
|
||||||
}, 2000);
|
|
||||||
});
|
|
||||||
|
|
||||||
const getCookieValue = (name) => (
|
function getCookie(name) {
|
||||||
document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || ''
|
const value = `; ${document.cookie}`;
|
||||||
)
|
const parts = value.split(`; ${name}=`);
|
||||||
|
if (parts.length === 2) return parts.pop().split(';').shift();
|
||||||
|
}
|
||||||
|
|
||||||
function getTokenFromCookie(tokenName) {
|
function getTokenFromCookie(tokenName) {
|
||||||
let tokenArray = getCookieValue(tokenName);
|
let cookieArray = getCookie(tokenName);
|
||||||
let decodedTokenArray = decodeURIComponent(tokenArray);
|
|
||||||
|
let decodedTokenArray = decodeURIComponent(cookieArray);
|
||||||
if (typeof decodedTokenArray !== 'string' || !decodedTokenArray) {
|
if (typeof decodedTokenArray !== 'string' || !decodedTokenArray) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let array = JSON.parse(decodedTokenArray);
|
let array = JSON.parse(decodedTokenArray, true);
|
||||||
if (Array.isArray(array)) {
|
|
||||||
return array['token'];
|
return array['token'];
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user