Clear Steam Wishlist

Removes all games from steam wishlist

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Clear Steam Wishlist
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Removes all games from steam wishlist
// @author       gortik
// @license      MIT
// @match        https://store.steampowered.com/wishlist/profiles/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=steampowered.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    addHTML();
    // Your code here...
})();

function addHTML() {
	let parentElem = document.querySelector( '.control_row' );
	parentElem.insertAdjacentHTML( 'beforeend', '<div class="filter_tab" id="clear_wishlist" style="margin-left: 15px;"><span>Clear</span></div>' );
	document.querySelector( '#clear_wishlist' ).addEventListener( 'click', clearWishlist );
}

// 1st remove wasnt detecting enter
async function pressEnter( ) {
	// create a new keyboard event and set the key to "Enter"
	const key_down = new KeyboardEvent( 'keydown', {
		key: 'Enter',
		code: 'Enter',
		which: 13,
		keyCode: 13,
	});

	const key_up = new KeyboardEvent( 'keyup', {
		key: 'Enter',
		code: 'Enter',
		which: 13,
		keyCode: 13,
	});

	// dispatch the event on some DOM element
	document.dispatchEvent( key_down );
	await sleep( 250 );
	document.dispatchEvent( key_up );
	await sleep( 250 );
}

async function confirmRemove() {
	if ( !document.querySelector('.newmodal') ) {
		console.log( 'Modal wasnt created.' );
		return;
	}
	document.querySelector('.newmodal .btn_green_steamui').click();
	await sleep( 500 );
}


function sleep( ms ) {
        return new Promise( resolve => {
		console.log( 'Sleep: ' + ms/1000 + 's.' );
		setTimeout( resolve, ms )
	});
}

async function clearWishlist() {
	let	games = document.querySelectorAll( '.delete' );

	for ( let remove_elem of games ) {
		remove_elem.click();
		await sleep( 1000 );
		// modal window with ok/cancel buttons
		if ( document.querySelector('.newmodal') )
			confirmRemove();
	}
}

addHTML()