Clorthax Script

Script for Clorthax's Summer Sale Quest 2022

2022-06-24 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Clorthax Script
// @version      1.0
// @description  Script for Clorthax's Summer Sale Quest 2022
// @author       duongoku
// @source       https://gist.github.com/duongoku/f8257fb783250e85e34f1ae9d1b30aec
// @match        https://store.steampowered.com/*
// @namespace https://github.com/duongoku/
// ==/UserScript==

async function do_quest() {
    console.log("Doing quest . . .");
    // Get quest data elements
    let application_config = document.querySelector("#application_config");
    let data_capsuleinsert = JSON.parse(
        application_config.attributes["data-capsuleinsert"].textContent
    );
    let data_community = JSON.parse(
        application_config.attributes["data-community"].textContent
    );
    let data_userinfo = JSON.parse(
        application_config.attributes["data-userinfo"].textContent
    );

    if (
        data_capsuleinsert == null ||
        data_community == null ||
        data_userinfo == null
    ) {
        return;
    }

    // Extract quest data
    let datarecord = data_capsuleinsert.datarecord;
    let door_index = data_capsuleinsert.payload;
    let clan_accountid = data_community.CLANACCOUNTID;
    let authwgtoken = data_userinfo.authwgtoken;

    // Map document cookie to an object
    let cookies = document.cookie.split("; ").reduce((acc, cookie) => {
        const [key, value] = cookie.split("=");
        acc[key] = value;
        return acc;
    }, {});

    // Extract session cookie
    let sessionid = cookies.sessionid;

    // Send request to complete quest
    await fetch("https://store.steampowered.com/saleaction/ajaxopendoor", {
        headers: {
            "content-type":
                "multipart/form-data; boundary=----WebKitFormBoundaryLMAO",
        },
        body:
            `------WebKitFormBoundaryLMAO\r\nContent-Disposition: form-data; name="sessionid"\r\n\r\n${sessionid}\r\n` +
            `------WebKitFormBoundaryLMAO\r\nContent-Disposition: form-data; name="authwgtoken"\r\n\r\n${authwgtoken}\r\n` +
            `------WebKitFormBoundaryLMAO\r\nContent-Disposition: form-data; name="datarecord"\r\n\r\n${datarecord}\r\n` +
            `------WebKitFormBoundaryLMAO\r\nContent-Disposition: form-data; name="door_index"\r\n\r\n${door_index}\r\n` +
            `------WebKitFormBoundaryLMAO\r\nContent-Disposition: form-data; name="clan_accountid"\r\n\r\n${clan_accountid}\r\n` +
            `------WebKitFormBoundaryLMAO--\r\n`,
        method: "POST",
        mode: "cors",
        credentials: "include",
    });

    window.location = "https://store.steampowered.com/sale/clorthax_quest";
}

function go_to_quest() {
    console.log("Going to quest page . . .");
    let button_click_me = document.querySelector(".Secondary.Focusable");
    if (button_click_me) {
        button_click_me.click();
    }

    let button_go_to_quest = document.querySelector(".Primary.Focusable");
    if (button_go_to_quest) {
        button_go_to_quest.click();
    } else {
        alert("YOUR QUEST IS FINISHED!");
        document.querySelector(".SummerSale2022_Header").firstChild.innerText =
            "YOUR QUEST IS FINISHED! THANKS FOR USING MY SCRIPT <3";
        document
            .querySelector(".SummerSale2022_Header")
            .parentElement.parentElement.scrollIntoView();
    }
}

if (
    `${window.location.origin}${window.location.pathname}`.startsWith(
        "https://store.steampowered.com/sale/clorthax_quest"
    )
) {
    document.onreadystatechange = go_to_quest;
}

let quest_list = [
    "https://store.steampowered.com/category/arcade_rhythm",
    "https://store.steampowered.com/category/arcade_rhythm/",
    "https://store.steampowered.com/category/casual",
    "https://store.steampowered.com/category/casual/",
    "https://store.steampowered.com/category/horror",
    "https://store.steampowered.com/category/horror/",
    "https://store.steampowered.com/category/multiplayer_coop",
    "https://store.steampowered.com/category/multiplayer_coop/",
    "https://store.steampowered.com/category/rpg",
    "https://store.steampowered.com/category/rpg/",
    "https://store.steampowered.com/category/simulation",
    "https://store.steampowered.com/category/simulation/",
    "https://store.steampowered.com/category/sports",
    "https://store.steampowered.com/category/sports/",
    "https://store.steampowered.com/category/strategy",
    "https://store.steampowered.com/category/strategy/",
    "https://store.steampowered.com/category/strategy_cities_settlements",
    "https://store.steampowered.com/category/strategy_cities_settlements/",
    "https://store.steampowered.com/vr",
    "https://store.steampowered.com/vr/",
];

if (
    quest_list.includes(`${window.location.origin}${window.location.pathname}`)
) {
    document.onreadystatechange = do_quest;
}