Skip to content

Instantly share code, notes, and snippets.

@xPaw
Created August 1, 2024 19:35
Show Gist options
  • Save xPaw/d5d974f42ce867a012bee1cc8add2b80 to your computer and use it in GitHub Desktop.
Save xPaw/d5d974f42ce867a012bee1cc8add2b80 to your computer and use it in GitHub Desktop.

Revisions

  1. xPaw created this gist Aug 1, 2024.
    49 changes: 49 additions & 0 deletions go-to-game-steam-achievements.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    // ==UserScript==
    // @name Go to recent Steam game achievements page
    // @namespace xpaw-go-to-recent-game-achievements
    // @match https://steamcommunity.com/*
    // @grant none
    // @version 1.0
    // @author xPaw
    // ==/UserScript==

    const popup = document.querySelector( '#account_dropdown .popup_body' );

    const optionsLink = document.createElement( 'a' );
    optionsLink.target = '_blank';
    optionsLink.className = 'popup_menu_item';
    optionsLink.textContent = 'Last Game Achievements';
    optionsLink.href = '#';
    optionsLink.addEventListener( 'click', ( e ) =>
    {
    e.preventDefault();

    optionsLink.textContent = 'Loading…';

    const applicationConfigElement = document.getElementById( 'application_config' );
    const applicationConfig = JSON.parse( applicationConfigElement.dataset.config );
    const userInfo = JSON.parse( applicationConfigElement.dataset.userinfo );
    const accessToken = JSON.parse( applicationConfigElement.dataset.loyalty_webapi_token );

    const params = new URLSearchParams();
    params.set( 'format', 'json' );
    params.set( 'access_token', accessToken );
    params.set( 'count', '1' );
    params.set( 'steamid', userInfo.steamid );

    fetch( `${applicationConfig.WEBAPI_BASE_URL}IPlayerService/GetRecentlyPlayedGames/v1/?${params.toString()}` )
    .then( ( response ) => response.json() )
    .then( ( response ) =>
    {
    if( !response || !response.response.games || !response.response.games || response.response.games.length < 1 )
    {
    return;
    }

    optionsLink.textContent = 'Redirecting…';

    window.location = `https://steamcommunity.com/profiles/${userInfo.steamid}/stats/${response.response.games[ 0 ].appid}/achievements/`;
    } );
    } );

    popup.appendChild( optionsLink );