Steam Wishlist Copy

Copy specified user's wishlist to your wishlist.

  1. // ==UserScript==
  2. // @name Steam Wishlist Copy
  3. // @namespace https://coding.net/u/sffxzzp
  4. // @version 0.10
  5. // @description Copy specified user's wishlist to your wishlist.
  6. // @author sffxzzp
  7. // @match *://store.steampowered.com/wishlist/*
  8. // @icon https://store.steampowered.com/favicon.ico
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. var util = (function () {
  13. function util() {}
  14. util.createElement = function (data) {
  15. var node;
  16. if (data.node) {
  17. node = document.createElement(data.node);
  18. if (data.content) {
  19. this.setElement({node: node, content: data.content});
  20. }
  21. if (data.html) {
  22. node.innerHTML = data.html;
  23. }
  24. }
  25. return node;
  26. };
  27. util.setElement = function (data) {
  28. if (data.node) {
  29. for (let name in data.content) {
  30. data.node.setAttribute(name, data.content[name]);
  31. }
  32. if (data.html!=undefined) {
  33. data.node.innerHTML = data.html;
  34. }
  35. }
  36. };
  37. return util;
  38. })();
  39. var swcopy = (function () {
  40. function swcopy() {};
  41. swcopy.prototype.addToWishlist = function (appid) {
  42. return new Promise((resolve, reject) => {
  43. var xhr = new XMLHttpRequest();
  44. xhr.open("post", 'https://store.steampowered.com/api/addtowishlist', true);
  45. xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
  46. xhr.responseType = "";
  47. xhr.timeout = 3e4;
  48. xhr.onload = function(ev) {
  49. var evt = ev.target;
  50. resolve(evt.response);
  51. };
  52. xhr.onerror = reject;
  53. xhr.ontimeout = reject;
  54. xhr.send(`sessionid=${unsafeWindow.g_sessionID}&appid=${appid}`);
  55. });
  56. };
  57. swcopy.prototype.run = function () {
  58. var _this = this;
  59. var searchBar = document.getElementsByClassName('controls')[0];
  60. var swcButton = util.createElement({node: "div", content: {class: "filter_tab settings_tab"}, html: "添加全部到愿望单"});
  61. swcButton.onclick = async function () {
  62. if (confirm("确定全部添加到愿望单?\n可能会有不可预料的后果。\n确定后请耐心等待。\n完成后会有弹窗提示。")) {
  63. for (var i=0;i<unsafeWindow.g_rgWishlistData.length;i++) {
  64. await _this.addToWishlist(unsafeWindow.g_rgWishlistData[i].appid);
  65. }
  66. alert("导入完成!");
  67. }
  68. }
  69. searchBar.appendChild(swcButton);
  70. };
  71. return swcopy
  72. })();
  73. (new swcopy()).run();
  74. })();