92 lines
3.4 KiB
JavaScript
92 lines
3.4 KiB
JavaScript
// ==UserScript==
|
|
// @name Mann Co. Store Giveaway Autojoiner
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 2026-08-21
|
|
// @description Tries to join giveaways on page load
|
|
// @author Abhorrent_Anger
|
|
// @include /^https?:\/\/mannco\.store\/giveaways.?$/
|
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=mannco.store
|
|
// @grant GM_xmlhttpRequest
|
|
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
|
|
// @require https://cdn.jsdelivr.net/gh/CoeJoder/waitForKeyElements.js@v1.3/waitForKeyElements.js
|
|
// @run-at document-end
|
|
// ==/UserScript==
|
|
|
|
setTimeout(function () { location.reload(); }, 90 * 60 * 1000);
|
|
|
|
const OPEN_GIVEAWAY_SELECTOR = '.giveaways-list-item:not(.giveaways-list-item--joined)';
|
|
|
|
waitForKeyElements('.giveaways__content', () => {
|
|
if ($(OPEN_GIVEAWAY_SELECTOR).len == 0) {
|
|
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 giveaway = /[^/]*$/.exec(giveawayURL)[0];
|
|
let giveawayJoinURL = 'https://api.mannco.store/giveaways/join/' + giveaway;
|
|
let xJoin = new GM_xmlhttpRequest({
|
|
method: 'POST',
|
|
url: giveawayJoinURL,
|
|
headers: { 'Authorization': 'Bearer ' + bearerToken, 'X-Csrf-Token': csrfToken },
|
|
onreadystatechange: function (response) {
|
|
if (response.readyState == 4) {
|
|
if (response.status == 200) {
|
|
console.log('Successfully joined ' + giveaway, response.response);
|
|
} else {
|
|
console.log("Couldn't join " + giveaway, response, bearerToken, csrfToken);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function getCookie(name) {
|
|
const value = `; ${document.cookie}`;
|
|
const parts = value.split(`; ${name}=`);
|
|
if (parts.length === 2) return parts.pop().split(';').shift();
|
|
}
|
|
|
|
function getTokenFromCookie(tokenName) {
|
|
let cookieArray = getCookie(tokenName);
|
|
|
|
let decodedTokenArray = decodeURIComponent(cookieArray);
|
|
if (typeof decodedTokenArray !== 'string' || !decodedTokenArray) {
|
|
return false;
|
|
}
|
|
let array = JSON.parse(decodedTokenArray, true);
|
|
return array['token'];
|
|
} |