Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eallion/c6423f30711b8d4704ff8372ec61715a to your computer and use it in GitHub Desktop.
Save eallion/c6423f30711b8d4704ff8372ec61715a to your computer and use it in GitHub Desktop.

User script to auto remove free games from your Steam account

ref: https://steamcommunity.com/sharedfiles/filedetails/?id=756281375

The Preface

I used this script[steamdb.info] to add all available games and DLC. The script was useful... It added some really interesting free games and DLC. But at the same time the script added a lot of uninteresting games/demos as well (more than 2500!)

And how can I remove these?!? Manually?!? More than 2500 games?!?
If there is the script to add, so should be a script to remove. But I haven't found....
So I wrote my own script. And after a few month, I had the time to write this guide to share the script

Attention!

Use this script at your own risk. If you decide that you don't want all that - not run the script. I'm not responsible for anything that happens to you and your account after using the script.

Script

RemoveScript Ver2.5.0 Eng

(function() {
	const delay = 100;
	const licensesUrl = `https://store.steampowered.com/account/licenses/`;
	const removeLicensesUrl = `https://store.steampowered.com/account/removelicense`;
    const warningString = 'Code cannot be executed here. You will be automatically redirected to the correct page. Please run this code on Steam\'s account page details: store.steampowered.com/account/licenses';
    const analysisHeader = 'Analyzing...';
    const analysisText = 'Please wait until analysis is complete.';
    const headerString = 'Games removing';
    const okString = 'Remove';
    const cancelString = 'Cancel';
    const mainInfo = 'You have  <b id="numberGames"></b> game(s) can be removed.<br/>Enter the number of games you want to remove.';
    const errorMessage = 'Enter number from 0 to ';
    const removingHeader = 'In Progress...';
    const removingText = 'Don\'t forget to say thanks if you like the script ;) Removed:';
	const noGamesToRemoveMessage = 'There are no games available for removing.'

	if (location.href != (licensesUrl)) {
        alert(warningString);
		window.location = (licensesUrl);
		return;
	}

    var freeLicensePackages = [];
    var modal = ShowBlockingWaitDialog(analysisHeader, analysisText);

	jQuery('.free_license_remove_link a').each(function(i, el) {
		var matched = decodeURI(el.href).match(/\d{4,}/);
		if (matched !== null) {
			freeLicensePackages.push(+matched);
		}
	});
	modal.Dismiss();

    var total = freeLicensePackages.length;
    if (total == 0) {
        alert(noGamesToRemoveMessage);
        return;
    }
    var enteredNumber = total;

    var desc = jQuery(`<div class="newmodal_prompt_description">${mainInfo}</div><div><div class="newmodal_prompt_input gray_bevel for_text_input fullwidth"><input type="text" id="games_number" value="0"/><span style="display: none; color: rgb(255, 0, 0);"><small>${errorMessage}${total}</small></span></div></div>`);
    var main = jQuery(`<div class="newmodal" style="position: fixed; z-index: 1000; max-width: 900px; left: 300px; top: 95px;"><div class="newmodal_header_border"><div class="newmodal_header"><div class="ellipsis">${headerString}</div></div></div><div class="newmodal_content_border"><div class="newmodal_content" style="max-height: 205px;"><div id="mainDiv"></div><div class="newmodal_buttons"><div class="btn_green_white_innerfade btn_medium"><span id="okButton">${okString}</span></div><div class="btn_grey_white_innerfade btn_medium"><span id="cancelButton">${cancelString}</span></div></div></div></div></div><div class="newmodal_background" style="opacity: 0.8;"></div>`);

    jQuery('body').append(main);
    jQuery('#cancelButton').on('click', function (event) {
        jQuery('.newmodal').remove();
        jQuery('.newmodal_background').remove();
    });
    jQuery('#mainDiv').html(desc);
    jQuery('#numberGames').text(total);
    jQuery('#games_number').val(total);
    jQuery('#games_number').on('change', function (event) {
        var input = jQuery(this);
        var value = +input.val();
        if (!Number.isInteger(value) || value > total || value <= 0) {
            input.css('border-color', 'red');
            input.next('span').show();
            jQuery('#okButton').hide();
        }
        else {
            enteredNumber = value;
            input.css('border-color', '');
            input.next('span').hide();
            jQuery('#okButton').show();
        }
	});

	var removed = 0;
	jQuery('#okButton').on('click', function (event) {
		jQuery('.newmodal').remove();
        jQuery('.newmodal_background').remove();
        proceed();
    });
	const proceed = () => {
        if (modal) {
            modal.Dismiss();
        }
        if (removed >= enteredNumber) {
			location.reload();
		}
		else {
			modal = ShowBlockingWaitDialog(removingHeader, `${removingText} <b>${removed}</b>/${enteredNumber}.`);
            deleteFunc(removed++);
		}
	};
    const deleteFunc = (index) => {
        jQuery.ajax({url: removeLicensesUrl,
			type: 'POST',
            dataType: 'text',
            data: { packageid: freeLicensePackages[index], sessionid: g_sessionID }}
		).done(setTimeout(() => proceed(), delay)).fail(fail);
    };
    const fail = (data) => {
        alert(data.responseText);
	}
}());

RemoveScript Ver1.0.2 Lite

This code removes all free games that you can remove, without dialog windows and checks.

(function()
{	var freeLicensePackages = [];
	var  modal = ShowBlockingWaitDialog('Analyze...',
	    	  'Please wait until analysis is complete.');
	jQuery('.free_license_remove_link a').each(function(i, el) {
		var matched = decodeURI(el.href).match(/\d{4,}/);
		if(matched !== null) {
			freeLicensePackages.push (+matched);
		}
	} );
	modal.Dismiss();
	var total = freeLicensePackages.length;
	alert('Don\'t forget to say thanks to the author of the script - niron (that\'s me;)');
	var removed = 0;
	for(var i = 0 ; i < total; i++ ) {
		jQuery.post('https://store' + '.steampowered.com/account/removelicense',
			{ packageid: freeLicensePackages[i], sessionid: g_sessionID }
		).always( function( ) {
				removed++;
				modal.Dismiss();
				if( removed >= total ) {
					location.reload();
				}
				else {
					modal = ShowBlockingWaitDialog( 'Executing…',
						'Don\'t forget to say thanks if You liked the script;) Removed <b>' + removed + '</b>/' + total + '.' );
				}
			}
		);
	}
}());

How to open the console in your browsers?

The script needs to be run from the console. How to open the development console in different browsers? If you suddenly forget it...)

Browsers Keys
Opera Ctrl + Shift + I
Chrome Ctrl + Shift + J or F12
Firefox Ctrl + Shift + K or F12
Internet Explorer F12, then click on the “Console” tab
Microsoft Edge F12, then click on the “Console” tab
Safari Cmd + Opt + C

How to use this?

It's easy!)
For example, I use Mozilla Firefox 48.0.2.

  1. Open your licenses and subscriptions page in your browser.
    You can go this way: "Account details >> View licenses and product key activations". Or you can launch the script on any page, and script will open the necessary page, where you need to launch the script again.
    And you need to be logged in of course.
  2. Open console in your browser
  3. Copy and run this code from the console
  4. When the analysis completes, you are prompted to remove all the available games (which have a delete button - as in the screenshot)
    If you click Remove, script will start removal process. Or you can change number of games you want to remove. If you click Cancel, the modal window will be closed.
    *Steam is changed: a limit was added on the number of requests from one IP address in a short period of time. As a result, you may get an error when removing more than 250 (according to Krad) games
  5. Then the page wiil be reloaded and... Enjoy :)
  6. If you get an error ("Access Denied" especially), try to decrese number of games to remove and run the script again.
  7. Then you can thank the author, rate, add to your favorites, and share with friends :)

Note

If you find a mistake in the text, or you have a good proposal to improve the guide or the script, I would be grateful if you inform me. Also I'll be very glad to your rank :)

Respect the work of others. No need to copy, modify, and distribute this information on your behalf. You can help change the guide and script and then share them with your friends.

Thanks for reading!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment