Steam one-click remove from wishlist

Allows you to remove an item from your Steam wishlist with one click on the "On Wishlist" button on the game's store page.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Steam one-click remove from wishlist
// @namespace    driver8.net
// @version      0.1
// @description  Allows you to remove an item from your Steam wishlist with one click on the "On Wishlist" button on the game's store page.
// @author       driver8
// @match        *://*.steampowered.com/app/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    console.log('hi steam wishlist');

    var nwl_button = document.querySelector('#add_to_wishlist_area > a');
    var owl_button = document.querySelector('.queue_actions_ctn > .queue_btn_active, #add_to_wishlist_area_success > a');

    if (nwl_button) {
        console.log('no-wishlist button', nwl_button);
        nwl_button.onclick = customAddToWishlist;
    } else if (owl_button) {
        console.log('on wishlist button', owl_button);
        owl_button.href = '#';
        owl_button.onclick = removeFromWishlist;
    }

    function removeFromWishlist(evt) {
        evt.preventDefault();
        evt.stopImmediatePropagation();
        evt.stopPropagation();
        var m1 = document.cookie.match(/steamRememberLogin=(\d+)/);
        var m2 = document.cookie.match(/steamLoginSecure=(\d+)/);
        var profile_id = (m1 && m1[1]) || (m2 && m2[1]);
        var m3 = document.cookie.match(/sessionid=([0-9a-f]+)/);
        var session_id = m3 && m3[1];
        var m4 = document.location.href.match(/store\.steampowered\.com\/app\/(\d+)/);
        var app_id = m4 && m4[1];

        if (profile_id && session_id && app_id) {
            var url = 'https://store.steampowered.com/wishlist/profiles/' + profile_id + '/remove/';
            console.log(url, session_id, app_id);
            var fd = new FormData();
            fd.set('appid', app_id);
            fd.set('sessionid', session_id);
            var oReq = new XMLHttpRequest();
            oReq.responseType = 'json';
            oReq.addEventListener("load", load_handler);
            oReq.open("POST", url);
            oReq.send(fd);
        }
        return false;
    }

    function load_handler(evt) {
        console.log('this', this);
        if (this.response && this.response.success == 1) {
            console.log('Successfully removed from wishlist');
            //owl_button.href = "javascript:AddToWishlist( parseInt(app_id), 'add_to_wishlist_area', 'add_to_wishlist_area_success', 'add_to_wishlist_area_fail', '' );";
            location.reload();
        }
    }

    function customAddToWishlist(evt) {
        var owl_button,
            i = 0;
        (function getButton() {
            owl_button = document.querySelector('.queue_actions_ctn > .queue_btn_active, #add_to_wishlist_area_success > a');
            console.log('on wishlist button', owl_button);
            if (!owl_button && i < 200) {
                console.log('try #', ++i);
                window.setTimeout(getButton, 20);
            } else {
                owl_button.onclick = removeFromWishlist;
            }
        })();
    }
})();