Steam愿望单重置

清空Steam愿望单 & 恢复Steam愿望单

目前为 2020-11-26 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Steam愿望单重置
  3. // @namespace steam-wishlist-reset
  4. // @version 1.0.1
  5. // @description 清空Steam愿望单 & 恢复Steam愿望单
  6. // @author HCLonely
  7. // @license MIT
  8. // @iconURL https://auto-task-test.hclonely.com/img/favicon.ico
  9. // @homepage https://github.com/HCLonely/steam-wishlist-reset
  10. // @supportURL https://github.com/HCLonely/steam-wishlist-reset/issues
  11. // @include *://store.steampowered.com/wishlist/profiles/*
  12. // @require https://cdn.jsdelivr.net/npm/sweetalert2@10.10.2/dist/sweetalert2.all.min.js
  13. // @require https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.5/runtime.min.js
  14. // @grant GM_setValue
  15. // @grant GM_getValue
  16. // @grant GM_deleteValue
  17. // @grant GM_addStyle
  18. // @grant GM_xmlhttpRequest
  19. // @grant GM_registerMenuCommand
  20. // @run-at document-end
  21. // ==/UserScript==
  22.  
  23. /* global GM_setValue,GM_getValue,GM_addStyle,GM_xmlhttpRequest,GM_registerMenuCommand,Swal,g_sessionID,g_AccountID,Blob,FileReader */
  24. (function () {
  25. GM_addStyle('#swal2-title{color:#000!important;}#swal2-content a{color:#2f89bc!important;}')
  26.  
  27. async function clearWishlist () {
  28. Swal.fire({
  29. title: '正在获取愿望单列表',
  30. text: '请耐心等待...'
  31. })
  32. const wishlistGames = await getWishlistFromServer()
  33.  
  34. if (wishlistGames?.length > 0) {
  35. const list = GM_setValue('list')?.length > 0 ? GM_setValue('list') : []
  36. const time = new Date().getTime()
  37. list.push(time)
  38. GM_setValue(time, wishlistGames)
  39. GM_setValue('list', list)
  40.  
  41. for (const gameId of wishlistGames) {
  42. await removeFromWishlist(gameId)
  43. }
  44.  
  45. Swal.fire({
  46. icon: 'success',
  47. title: '愿望单清空完成(忽略所有错误)',
  48. confirmButtonText: '保存愿望单数据到本地',
  49. showCancelButton: true,
  50. cancelButtonText: '关闭'
  51. }).then(({
  52. value
  53. }) => {
  54. if (value) {
  55. createAndDownloadFile('wishlists.json', JSON.stringify(wishlistGames))
  56. }
  57. })
  58. } else {
  59. Swal.fire({
  60. icon: 'warning',
  61. title: '愿望单为空!'
  62. })
  63. }
  64. }
  65.  
  66. function removeFromWishlist (gameId) {
  67. return new Promise(resolve => {
  68. Swal.update({
  69. title: '正在移除愿望单游戏',
  70. text: gameId
  71. })
  72. GM_xmlhttpRequest({
  73. url: 'https://store.steampowered.com/api/removefromwishlist',
  74. method: 'POST',
  75. headers: {
  76. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  77. },
  78. data: `sessionid=${g_sessionID}&appid=${gameId}`,
  79. responseType: 'json',
  80. onload: response => {
  81. console.log(response)
  82. resolve()
  83. },
  84. ontimeout: resolve,
  85. onerror: resolve,
  86. onabort: resolve
  87. })
  88. })
  89. }
  90.  
  91. async function recoverWishlist (games) {
  92. if (!games) {
  93. games = await getWishlistFromLocal()
  94. }
  95.  
  96. if (games) {
  97. const failedGames = []
  98.  
  99. for (const gameId of games) {
  100. if (!(await addToWishlist(gameId))) failedGames.push(gameId)
  101. }
  102.  
  103. console.log('恢复失败的游戏:', failedGames)
  104. Swal.fire({
  105. icon: 'success',
  106. title: '愿望单恢复完成,恢复失败的游戏:',
  107. html: JSON.stringify(failedGames).replace(/[\d]+/g, function (gameId) {
  108. return `<a href=https://store.steampowered.com/app/${gameId} target="_blank">${gameId}</a>`
  109. }),
  110. confirmButtonText: '重新恢复失败的游戏',
  111. showCancelButton: true,
  112. cancelButtonText: '关闭'
  113. }).then(({
  114. value
  115. }) => {
  116. if (value) {
  117. recoverWishlist(failedGames)
  118. }
  119. })
  120. } else {
  121. Swal.fire({
  122. icon: 'error',
  123. title: '没有读取到游戏列表'
  124. })
  125. }
  126. }
  127.  
  128. function addToWishlist (gameId) {
  129. return new Promise(resolve => {
  130. Swal.update({
  131. title: '正在恢复愿望单游戏',
  132. text: gameId
  133. })
  134. GM_xmlhttpRequest({
  135. url: 'https://store.steampowered.com/api/addtowishlist',
  136. method: 'POST',
  137. headers: {
  138. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  139. },
  140. data: `sessionid=${g_sessionID}&appid=${gameId}`,
  141. responseType: 'json',
  142. onload: response => {
  143. console.log(response)
  144.  
  145. if (response.status === 200 && response.response?.success === true) {
  146. resolve(true)
  147. } else {
  148. resolve(false)
  149. }
  150. },
  151. ontimeout: () => {
  152. resolve(false)
  153. },
  154. onerror: () => {
  155. resolve(false)
  156. },
  157. onabort: () => {
  158. resolve(false)
  159. }
  160. })
  161. })
  162. }
  163.  
  164. function createAndDownloadFile (fileName, content) {
  165. const aTag = document.createElement('a')
  166. const blob = new Blob([content])
  167. aTag.download = fileName
  168. aTag.href = URL.createObjectURL(blob)
  169. aTag.click()
  170. URL.revokeObjectURL(blob)
  171. }
  172.  
  173. function getWishlistFromServer () {
  174. return new Promise(resolve => {
  175. GM_xmlhttpRequest({
  176. method: 'GET',
  177. url: 'https://store.steampowered.com/dynamicstore/userdata/?id=' + g_AccountID + '&cc=CN&v=70',
  178. nocache: true,
  179. responseType: 'json',
  180. onload: async response => {
  181. console.log(response)
  182.  
  183. if (response.status === 200 && response?.response?.rgWishlist) {
  184. resolve(response.response.rgWishlist)
  185. } else {
  186. Swal.fire({
  187. icon: 'error',
  188. title: '获取愿望单列表失败!'
  189. })
  190. resolve(false)
  191. }
  192. },
  193. ontimeout: e => {
  194. console.log(e)
  195. Swal.fire({
  196. icon: 'error',
  197. title: '获取愿望单列表失败!'
  198. })
  199. resolve(false)
  200. },
  201. onerror: e => {
  202. console.log(e)
  203. Swal.fire({
  204. icon: 'error',
  205. title: '获取愿望单列表失败!'
  206. })
  207. resolve(false)
  208. },
  209. onabort: e => {
  210. console.log(e)
  211. Swal.fire({
  212. icon: 'error',
  213. title: '获取愿望单列表失败!'
  214. })
  215. resolve(false)
  216. }
  217. })
  218. })
  219. }
  220.  
  221. async function getWishlistFromLocal () {
  222. let games
  223. const type = await Swal.fire({
  224. confirmButtonText: '从缓存中读取',
  225. showDenyButton: true,
  226. denyButtonText: '从文件中读取'
  227. }).then(result => {
  228. if (result.isConfirmed) {
  229. return 'cache'
  230. } else if (result.isDenied) {
  231. return 'file'
  232. }
  233. })
  234.  
  235. if (type === 'cache') {
  236. Swal.fire({
  237. title: '正在读取愿望单列表',
  238. text: '请稍等...'
  239. })
  240. const list = GM_getValue('list')
  241. const listId = list ? list[list.length - 1] : null
  242. games = listId ? GM_getValue(listId) : null
  243. } else if (type === 'file') {
  244. const {
  245. value: file
  246. } = await Swal.fire({
  247. title: '请选择要读取的文件',
  248. input: 'file',
  249. inputAttributes: {
  250. accept: 'application/json',
  251. 'aria-label': '上传你的愿望单列表'
  252. }
  253. })
  254.  
  255. if (file) {
  256. Swal.fire({
  257. title: '正在读取愿望单列表',
  258. text: '如果长时间没反应,请打开控制台查看报错'
  259. })
  260. games = await new Promise(resolve => {
  261. const reader = new FileReader()
  262.  
  263. reader.onload = e => {
  264. resolve(JSON.parse(e.target.result))
  265. }
  266.  
  267. reader.onerror = e => {
  268. resolve(false)
  269. }
  270.  
  271. reader.readAsText(file)
  272. })
  273. }
  274. }
  275.  
  276. return games
  277. }
  278.  
  279. GM_registerMenuCommand('清空愿望单', clearWishlist)
  280. GM_registerMenuCommand('恢复愿望单', recoverWishlist)
  281. })()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址