Clear Steam Wishlist

Removes all games from steam wishlist

  1. // ==UserScript==
  2. // @name Clear Steam Wishlist
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Removes all games from steam wishlist
  6. // @author gortik
  7. // @license MIT
  8. // @match https://store.steampowered.com/wishlist/profiles/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=steampowered.com
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. addHTML();
  16. // Your code here...
  17. })();
  18.  
  19. function addHTML() {
  20. let parentElem = document.querySelector( '.control_row' );
  21. parentElem.insertAdjacentHTML( 'beforeend', '<div class="filter_tab" id="clear_wishlist" style="margin-left: 15px;"><span>Clear</span></div>' );
  22. document.querySelector( '#clear_wishlist' ).addEventListener( 'click', clearWishlist );
  23. }
  24.  
  25. // 1st remove wasnt detecting enter
  26. async function pressEnter( ) {
  27. // create a new keyboard event and set the key to "Enter"
  28. const key_down = new KeyboardEvent( 'keydown', {
  29. key: 'Enter',
  30. code: 'Enter',
  31. which: 13,
  32. keyCode: 13,
  33. });
  34.  
  35. const key_up = new KeyboardEvent( 'keyup', {
  36. key: 'Enter',
  37. code: 'Enter',
  38. which: 13,
  39. keyCode: 13,
  40. });
  41.  
  42. // dispatch the event on some DOM element
  43. document.dispatchEvent( key_down );
  44. await sleep( 250 );
  45. document.dispatchEvent( key_up );
  46. await sleep( 250 );
  47. }
  48.  
  49. async function confirmRemove() {
  50. if ( !document.querySelector('.newmodal') ) {
  51. console.log( 'Modal wasnt created.' );
  52. return;
  53. }
  54. document.querySelector('.newmodal .btn_green_steamui').click();
  55. await sleep( 500 );
  56. }
  57.  
  58.  
  59. function sleep( ms ) {
  60. return new Promise( resolve => {
  61. console.log( 'Sleep: ' + ms/1000 + 's.' );
  62. setTimeout( resolve, ms )
  63. });
  64. }
  65.  
  66. async function clearWishlist() {
  67. let games = document.querySelectorAll( '.delete' );
  68.  
  69. for ( let remove_elem of games ) {
  70. remove_elem.click();
  71. await sleep( 1000 );
  72. // modal window with ok/cancel buttons
  73. if ( document.querySelector('.newmodal') )
  74. confirmRemove();
  75. }
  76. }
  77.  
  78. addHTML()