Groupees - Keys Exporter

Export steam keys and mark them as used

当前为 2017-02-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Groupees - Keys Exporter
  3. // @icon https://groupees.com/favicon.ico
  4. // @namespace Royalgamer06
  5. // @author Royalgamer06
  6. // @version 1.1.7
  7. // @description Export steam keys and mark them as used
  8. // @include *://groupees.com/*
  9. // @grant unsafeWindow
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
  11. // ==/UserScript==
  12.  
  13. //CONFIGURATION
  14. //Mark keys as used when exporting?
  15. const markUsed = true;
  16. //Export purchased products that have been revealed already too?
  17. const includeRevealed = true;
  18. //Add a white line between each item in the export window?
  19. const addWhiteLine = true;
  20. //Put the key on a new line after the game name?
  21. const keyOnNewLine = true;
  22. //What separates the game name and the key?
  23. const keySeparator = "";
  24.  
  25. //CODE
  26. this.$ = this.jQuery = jQuery.noConflict(true);
  27. $(document).ready(function() {
  28. init();
  29. });
  30.  
  31. function init() {
  32. if (/^https?:\/\/groupees\.com\/purchases\/?((\?|#).*)?$/.test(location.href)) {
  33. addExportButtonOld();
  34. }
  35. if (/^https?:\/\/groupees\.com\/profile\/products\/?((\?|#).*)?$/.test(location.href)) {
  36. addExportButtonNew();
  37. }
  38. }
  39.  
  40. function addExportButtonNew() {
  41. $("#product_filters .col-md-3:last").append('<a class="btn btn-block btn-export-products"><span class="g-icon-2x g-icon-external-link"></span> Export Keys</a>');
  42. $(".btn-export-products").click(exportNew);
  43. }
  44.  
  45. function exportNew() {
  46. $(".btn-export-products").html('<span class="g-icon-2x g-icon-spinner" style="display: inline-block;"></span> Exporting...').attr("disabled", "disabled");
  47. var deg = 0;
  48. var spinner = setInterval(function() {
  49. if ($(".btn-export-products .g-icon-spinner").length > 0) {
  50. deg++;
  51. $(".btn-export-products .g-icon-spinner").css("transform", "rotate(" + deg + "deg)").css("-webkit-transform", "rotate(" + deg + "deg)").css("-moz-transform", "rotate(" + deg + "deg)").css("-o-transform", "rotate(" + deg + "deg)");
  52. } else {
  53. clearInterval(spinner);
  54. }
  55. }, 5);
  56. var filters = "";
  57. $(".product-filter-options input:checked").each(function() {
  58. filters += "&" + this.id.replace("_", "=");
  59. });
  60. loadNextPages(1, [], filters);
  61. }
  62.  
  63. function continueExportNew(productData) {
  64. unsafeWindow.productData = productData;
  65. var exportData = [];
  66. var productCount = productData.length;
  67. var ajaxCount = productCount;
  68. $(productData).each(function(index) {
  69. let i = index;
  70. let pid = this.pid;
  71. let game = this.game;
  72. if (!(this.revealed || !includeRevealed)) {
  73. unsafeWindow.$.post("/user_products/" + pid + "/reveal", function() {
  74. unsafeWindow.$.ajax({
  75. url: "/profile/products/" + pid,
  76. type: "GET",
  77. dataType: "script",
  78. success: function(s) {
  79. if (s.match(/data-id=\\\'[0-9]+\\\'>\\n/g) !== null) {
  80. let kid = s.match(/data-id=\\\'[0-9]+\\\'>\\n/g)[0].split("\\'")[1];
  81. unsafeWindow.$.post("/activation_codes/" + kid + "/reveal", function(data) {
  82. let key = data.code;
  83. exportData.push({ game: game, key: key });
  84. unsafeWindow.exportData = exportData;
  85. if (markUsed) unsafeWindow.$.post("/activation_codes/" + kid + "/lock");
  86. }).always(function() {
  87. ajaxCount--;
  88. unsafeWindow.ajaxCount = ajaxCount;
  89. if (1 === ajaxCount) {
  90. setTimeout(function() {
  91. var win = unsafeWindow.open("", "Groupees Keys Export", "width=480,height=640");
  92. $(exportData.sort(SortByGame)).each(function() {
  93. win.document.write(this.game + keySeparator + (keyOnNewLine ? "<br>" : "") + this.key + (addWhiteLine ? "<br><br>" : "<br>"));
  94. });
  95. selectAll(win);
  96. $(".btn-export-products").html('<span class="g-icon-2x g-icon-external-link"></span> Export Keys').removeAttr("disabled");
  97. }, 1000);
  98. }
  99. });
  100. }
  101. },
  102. error: function() {
  103. ajaxCount--;
  104. }
  105. });
  106. }).fail(function() {
  107. ajaxCount--;
  108. });
  109. }
  110. });
  111. }
  112.  
  113. function loadNextPages(page, productData, filters) {
  114. $.ajax({
  115. url: "/profile/products?page=" + page + filters,
  116. type: "GET",
  117. success: function(data) {
  118. data = data.replace(/<img\b[^>]*>/ig, "");
  119. if ($("#products_loader", data).length > 0) {
  120. $(".product-cell:has(.g-icon-game)", data).each(function() {
  121. var pid = $(this).attr("data-id");
  122. var game = $(this).find("h4[title]").attr("title");
  123. var revealed = $(this).find(".btn-reveal-product").length > 0;
  124. productData.push({ pid: pid, game: game, revealed: revealed });
  125. });
  126. loadNextPages(page + 1, productData, filters);
  127. } else {
  128. continueExportNew(productData);
  129. }
  130. }
  131. });
  132. }
  133.  
  134. function addExportButtonOld() {
  135. $(".pre-nav").append('<button style="float:right;" id="exportUnused">Export Unused Keys</button>');
  136. $("#exportUnused").click(exportUnusedOld);
  137. }
  138.  
  139. function exportUnusedOld() {
  140. var win = unsafeWindow.open("", "Groupees Keys Export", "width=480,height=640");
  141. $(".code:not([disabled])").each(function() {
  142. if (markUsed) $(this).parents(".product").find(".usage").click();
  143. win.document.write($(this).parents(".product").find("h3").text() + keySeparator + (keyOnNewLine ? "<br>" : "") + $(this).val() + (addWhiteLine ? "<br><br>" : "<br>"));
  144. });
  145. selectAll(win);
  146. }
  147.  
  148. function selectAll(win) {
  149. var range = win.document.createRange();
  150. range.selectNodeContents(win.document.body);
  151. var selection = win.window.getSelection();
  152. selection.removeAllRanges();
  153. selection.addRange(range);
  154. }
  155.  
  156. function SortByGame(a, b){
  157. var aName = a.game.toLowerCase();
  158. var bName = b.game.toLowerCase();
  159. return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
  160. }