Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed delay not working + added ETA + vanilla javascript (no jQuery) #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,39 @@
<a href="https://ibb.co/D55WXk5"><img src="https://i.ibb.co/LnnRw6n/Sans-titre-modified.png" alt="Sans-titre-modified" border="0"></a>
<br>
<br>
Version: 1.1
Version: 1.2
<br>
</h1>





# Description:
# Description

This Script will remove any "Free" games from your Steam Library by removing the game's license from your account. In this way, these games will no longer appear in your library.

# Usage:
# Usage

1. Copy the script to your clipboard.
2. Open your browser and go to https://store.steampowered.com/account/licenses/
2. Open your browser and go to <https://store.steampowered.com/account/licenses/>
3. Open the developer console (F12)
4. Paste the script into the console and press enter.
5. Wait for the script to finish.
6. Refresh the page. ( You may need to do this refresh with the cache, you can do this by pressing CTRL + F5 )

# Notes:
# Notes

- This script will not remove any games that you have purchased.
- This script will not remove any games that you have been gifted.

# Disclaimer:
# Disclaimer

- This script is provided as is. I am not responsible for any damage that may occur to your account. Use at your own risk.
- Don't change the script, especially the interval time, if you do, your browser's access to your profile settings page may be blocked by Steam for a few seconds or minutes.

# Changelog

# Changelog:

- 1.0 - Initial Release
- 1.1 - Added a delay between each request to avoid being blocked by Steam.
- 1.0 - Initial Release
- 1.1 - Added a delay between each request to avoid being blocked by Steam.
- 1.2 - Fixed delay not working + added ETA + vanilla javascript (no jQuery)

# Credits:
# Credits

- SteamDB - https://steamdb.info/
- SteamDB - <https://steamdb.info/>
53 changes: 25 additions & 28 deletions SteamLicenseRemover.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
// ==UserScript==
// @name Steam License Remover
// @namespace
// @version 1.1
// @description Remove any "Free" games from your Steam Library by removing the game's license from your account.
// @version 1.2
// @description Remove any "Free" games from your Steam Library by removing the game's license from your account.
// @author IroN404
// @match https://store.steampowered.com/account/licenses/


const table = document.querySelector('.account_table');
const rows = table.querySelectorAll('tr');
const total = rows.length;
const removeLinkEls = document.querySelectorAll('.free_license_remove_link > a');
let itemIds = [];

removeLinkEls.forEach(el => itemIds.push(el.getAttribute('href').match(/\d+/)[0]));

const total = itemIds.length;
console.log(`Starting removal of ${total} entries`);
const start = Date.now();

let removed = 0;
const intervalId = setInterval(() => {
rows.forEach(row => {
const div = row.querySelector('.free_license_remove_link');
if(div) {
const removeLink = div.querySelector('a');
if (removeLink) {
removed += 1;
const link = removeLink.getAttribute('href');
const id = link.split('(')[1].split(',')[0].trim();
jQuery.post(
'https://store.steampowered.com/account/removelicense',
{
sessionid: g_sessionID,
packageid: id
}
);
}
}
const intervalId = setInterval(async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can still cause issues if the fetch calls take longer than 2 seconds to complete, use setTimeout after the fetch completes instead.

const currentId = itemIds.pop();
const response = await fetch('https://store.steampowered.com/account/removelicense', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `sessionid=${g_sessionID}&packageid=${currentId}`
Copy link

@xPaw xPaw Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use FormData (and then you don't need to specify the content type iirc)

});
if (!response.ok) console.error(response);

if (removed === total) {
console.log(`All ${total} licenses removed!`);
removed++;

if (!itemIds.length) {
console.info(`All ${total} licenses removed!`);
clearInterval(intervalId);
}
if (removed < total) {
console.log(`Removed ${removed} of ${total} licenses.`);
} else {
const now = Date.now();
const remaining = Math.floor((now - start) / removed * (total - removed));
console.info(`Removed ${removed} of ${total} licenses. ETA: ${new Date(now + remaining).toLocaleTimeString()}`);
}
}, 2000);