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