HumbleBundle - Unredeemed Game List Compiler

Compiles a list of the unredeemed games

当前为 2022-11-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name HumbleBundle - Unredeemed Game List Compiler
  3. // @description Compiles a list of the unredeemed games
  4. // @version 2022.09.19.11.12
  5. // @author MetalTxus
  6. // @namespace https://github.com/jesuscc1993
  7.  
  8. // @icon https://cdn.humblebundle.com/static/hashed/46cf2ed85a0641bfdc052121786440c70da77d75.png
  9. // @match https://www.humblebundle.com/home/keys
  10. // @require https://code.jquery.com/jquery-3.6.1.min.js
  11. // ==/UserScript==
  12.  
  13. /* globals jQuery */
  14.  
  15. (() => {
  16. 'use strict';
  17.  
  18. let games;
  19.  
  20. const compileGamesList = () => {
  21. games = [];
  22.  
  23. jQuery('#hide-redeemed:not(:checked)').click();
  24. jQuery('.jump-to-page[data-index="0"]').click();
  25.  
  26. setTimeout(processPage, 150);
  27. }
  28.  
  29. const processPage = () => {
  30. jQuery('.game-name h4').each((i, e) => {
  31. const name = e.textContent;
  32. const link = `https://store.steampowered.com/search/?term=${encodeURI(name)}`;
  33.  
  34. games.push(`
  35. <li>
  36. <a href="${link}" target="_blank">
  37. ${name}
  38. </a>
  39. </li>
  40. `);
  41. });
  42.  
  43. const nextPage = jQuery('.jump-to-page.current').next();
  44. if (nextPage.length) {
  45. jQuery('.jump-to-page.current').next().click();
  46. processPage();
  47. } else {
  48. outputGames();
  49. }
  50. }
  51.  
  52. const outputGames = () => {
  53. const html = `
  54. <!DOCTYPE html>
  55. <html>
  56. <head>
  57. <title>Unredeemed HumbleBundle Games List</title>
  58. <link href="https://cdn.humblebundle.com/static/hashed/46cf2ed85a0641bfdc052121786440c70da77d75.png" rel="icon" />
  59. <style>
  60. ul {
  61. list-style: none;
  62. margin: 0;
  63. padding: 0;
  64. }
  65. </style>
  66. </head>
  67.  
  68. <body>
  69. <ul>
  70. ${games.sort().join('')}
  71. </ul>
  72.  
  73. <p>
  74. <small>Unredeemed games count: ${games.length}</small>
  75. </p>
  76. </body>
  77. </html>
  78. `;
  79. downloadFile(html, 'unredeemed-humblebundle-games-list.html', 'text/plain');
  80. }
  81.  
  82. const downloadFile = (content, fileName, type) => {
  83. const file = new Blob([content], { type });
  84. const href = URL.createObjectURL(file);
  85. jQuery(`<a href="${href}" download="${fileName}">`)[0].click();
  86. };
  87.  
  88. const initialize = () => {
  89. jQuery('head').append(`
  90. <style>
  91. .generate-list-button {
  92. background:#f1f3f6;
  93. border:1px solid #ccc;
  94. padding:0 12px;
  95. }
  96. </style>
  97. `);
  98.  
  99. const button = jQuery(`
  100. <button class="generate-list-button">
  101. Compile unredeemed games list
  102. </button>
  103. `);
  104. button.click(compileGamesList);
  105. jQuery('.search').before(button);
  106. }
  107.  
  108. setTimeout(initialize, 150);
  109. })();