Steam Wishlist Copy

Copy specified user's wishlist to your wishlist.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Steam Wishlist Copy
// @namespace    https://coding.net/u/sffxzzp
// @version      0.10
// @description  Copy specified user's wishlist to your wishlist.
// @author       sffxzzp
// @match        *://store.steampowered.com/wishlist/*
// @icon         https://store.steampowered.com/favicon.ico
// ==/UserScript==

(function() {
    var util = (function () {
        function util() {}
        util.createElement = function (data) {
            var node;
            if (data.node) {
                node = document.createElement(data.node);
                if (data.content) {
                    this.setElement({node: node, content: data.content});
                }
                if (data.html) {
                    node.innerHTML = data.html;
                }
            }
            return node;
        };
        util.setElement = function (data) {
            if (data.node) {
                for (let name in data.content) {
                    data.node.setAttribute(name, data.content[name]);
                }
                if (data.html!=undefined) {
                    data.node.innerHTML = data.html;
                }
            }
        };
        return util;
    })();
    var swcopy = (function () {
        function swcopy() {};
        swcopy.prototype.addToWishlist = function (appid) {
            return new Promise((resolve, reject) => {
                var xhr = new XMLHttpRequest();
                xhr.open("post", 'https://store.steampowered.com/api/addtowishlist', true);
                xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
                xhr.responseType = "";
                xhr.timeout = 3e4;
                xhr.onload = function(ev) {
                    var evt = ev.target;
                    resolve(evt.response);
                };
                xhr.onerror = reject;
                xhr.ontimeout = reject;
                xhr.send(`sessionid=${unsafeWindow.g_sessionID}&appid=${appid}`);
            });
        };
        swcopy.prototype.run = function () {
            var _this = this;
            var searchBar = document.getElementsByClassName('controls')[0];
            var swcButton = util.createElement({node: "div", content: {class: "filter_tab settings_tab"}, html: "添加全部到愿望单"});
            swcButton.onclick = async function () {
                if (confirm("确定全部添加到愿望单?\n可能会有不可预料的后果。\n确定后请耐心等待。\n完成后会有弹窗提示。")) {
                    for (var i=0;i<unsafeWindow.g_rgWishlistData.length;i++) {
                        await _this.addToWishlist(unsafeWindow.g_rgWishlistData[i].appid);
                    }
                    alert("导入完成!");
                }
            }
            searchBar.appendChild(swcButton);
        };
        return swcopy
    })();
    (new swcopy()).run();
})();