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.4
  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. $(productData).each(function(index) {
  68. let i = index;
  69. let pid = this.pid;
  70. let game = this.game;
  71. if (!(this.revealed || !includeRevealed)) {
  72. unsafeWindow.$.post("/user_products/" + pid + "/reveal", function() {
  73. unsafeWindow.$.ajax({
  74. url: "/profile/products/" + pid,
  75. type: "GET",
  76. dataType: "script",
  77. success: function(s) {
  78. if (s.match(/data-id=\\\'[0-9]+\\\'>\\n/g) !== null) {
  79. let kid = s.match(/data-id=\\\'[0-9]+\\\'>\\n/g)[0].split("\\'")[1];
  80. unsafeWindow.$.post("/activation_codes/" + kid + "/reveal", function(data) {
  81. let key = data.code;
  82. exportData.push({ game: game, key: key });
  83. unsafeWindow.exportData = exportData;
  84. if (markUsed) unsafeWindow.$.post("/activation_codes/" + kid + "/lock");
  85. }).always(function() {
  86. if (i === productCount - 1) {
  87. setTimeout(function() {
  88. var win = window.open("", "Groupees Keys Export", "width=480,height=640");
  89. $(exportData.sort(SortByGame)).each(function() {
  90. win.document.write(this.game + keySeparator + (keyOnNewLine ? "<br>" : "") + this.key + (addWhiteLine ? "<br><br>" : "<br>"));
  91. });
  92. selectAll(win);
  93. $(".btn-export-products").html('<span class="g-icon-2x g-icon-external-link"></span> Export Keys').removeAttr("disabled");
  94. }, 1000);
  95. }
  96. });
  97. }
  98. }
  99. });
  100. });
  101. }
  102. });
  103. }
  104.  
  105. function loadNextPages(page, productData, filters) {
  106. $.ajax({
  107. url: "/profile/products?page=" + page + filters,
  108. type: "GET",
  109. success: function(data) {
  110. if ($("#products_loader", data).length > 0) {
  111. $(".product-cell:has(.g-icon-game)", data).each(function() {
  112. var pid = $(this).attr("data-id");
  113. var game = $(this).find("h4[title]").attr("title");
  114. var revealed = $(this).find(".btn-reveal-product").length > 0;
  115. productData.push({ pid: pid, game: game, revealed: revealed });
  116. });
  117. loadNextPages(page + 1, productData, filters);
  118. } else {
  119. continueExportNew(productData);
  120. }
  121. }
  122. });
  123. }
  124.  
  125. function addExportButtonOld() {
  126. $(".pre-nav").append('<button style="float:right;" id="exportUnused">Export Unused Keys</button>');
  127. $("#exportUnused").click(exportUnusedOld);
  128. }
  129.  
  130. function exportUnusedOld() {
  131. var win = window.open("", "Groupees Keys Export", "width=480,height=640");
  132. $(".code:not([disabled])").each(function() {
  133. if (markUsed) $(this).parents(".product").find(".usage").click();
  134. win.document.write($(this).parents(".product").find("h3").text() + keySeparator + (keyOnNewLine ? "<br>" : "") + $(this).val() + (addWhiteLine ? "<br><br>" : "<br>"));
  135. });
  136. selectAll(win);
  137. }
  138.  
  139. function selectAll(win) {
  140. var range = win.document.createRange();
  141. range.selectNodeContents(win.document.body);
  142. var selection = win.window.getSelection();
  143. selection.removeAllRanges();
  144. selection.addRange(range);
  145. }
  146.  
  147. function SortByGame(a, b){
  148. var aName = a.game.toLowerCase();
  149. var bName = b.game.toLowerCase();
  150. return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
  151. }