steam-game-deleter/site_script.js
Timo Hocker d83c6b7efe
init
2024-06-26 13:05:30 +02:00

210 lines
9.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function() {
const delay = 500;
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.'
const rateLimitedMessage = 'You have been rate limited, try again later!'
const errorMessage2 = 'An error was encountered while processing your request:'
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',
data: { packageid: freeLicensePackages[index], sessionid: g_sessionID },
success: function ( response ) {
if ( response.success == 1 ) {
setTimeout(() => proceed(), delay)
}
else {
modal.Dismiss();
if (response.success = 84)
ShowAlertDialog( 'Error', rateLimitedMessage + ' Error: ' + response.success);
else
ShowAlertDialog( 'Error', errorMessage2 + ' ' + response.success);
... (5 lines left)
Collapse
message.txt
5 KB

(function() {
const delay = 500;
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.'
const rateLimitedMessage = 'You have been rate limited, try again later!'
const errorMessage2 = 'An error was encountered while processing your request:'
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',
data: { packageid: freeLicensePackages[index], sessionid: g_sessionID },
success: function ( response ) {
if ( response.success == 1 ) {
setTimeout(() => proceed(), delay)
}
else {
modal.Dismiss();
if (response.success = 84)
ShowAlertDialog( 'Error', rateLimitedMessage + ' Error: ' + response.success);
else
ShowAlertDialog( 'Error', errorMessage2 + ' ' + response.success);
}
}
})
};
}());