Clear Steam Wishlist

Removes all games from steam wishlist

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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()