JSON parse check

This commit is contained in:
Abhorrent_Anger 2026-08-16 20:50:42 +03:00
parent 48a40b8058
commit f591963fb6

View File

@ -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-16 // @version 2026-08-17
// @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.?$/
@ -21,8 +21,8 @@ waitForKeyElements('.giveaways__content', () => {
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 = getToken('auth'); let bearerToken = getTokenFromCookie('auth');
let csrfToken = getToken('csrf'); let csrfToken = getTokenFromCookie('csrf');
let xJoin = new GM_xmlhttpRequest({ let xJoin = new GM_xmlhttpRequest({
method: 'POST', method: 'POST',
@ -45,8 +45,12 @@ const getCookieValue = (name) => (
document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || '' document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || ''
) )
function getToken(tokenName) { function getTokenFromCookie(tokenName) {
let authArray = getCookieValue(tokenName); let authArray = getCookieValue(tokenName);
let decodedAuthArray = decodeURIComponent(authArray); let decodedAuthArray = decodeURIComponent(authArray);
return JSON.parse(decodedAuthArray)['token']; let array = JSON.parse(decodedAuthArray)
if (array.isArray()) {
return array['token'];
}
return false;
} }