Groupees - Keys Exporter

Export steam keys and mark them as used

目前為 2017-02-10 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Groupees - Keys Exporter
  3. // @icon https://groupees.com/favicon.ico
  4. // @namespace Royalgamer06
  5. // @author Royalgamer06
  6. // @version 1.1.0
  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. if (markUsed) unsafeWindow.$.post("/activation_codes/" + kid + "/lock");
  79. if (i === productCount - 1) {
  80. var win = window.open("", "Groupees Keys Export", "width=480,height=640");
  81. $(exportData.sort(SortByGame)).each(function() {
  82. win.document.write(this.game + keySeparator + (keyOnNewLine ? "<br>" : "") + this.key + (addWhiteLine ? "<br><br>" : "<br>"));
  83. });
  84. selectAll(win);
  85. $(".btn-export-products").html('<span class="g-icon-2x g-icon-external-link"></span> Export Keys').removeAttr("disabled");
  86. }
  87. });
  88. }
  89. }
  90. });
  91. });
  92. }
  93. });
  94. }
  95.  
  96. function loadNextPages() {
  97. if ($("#products_loader").length > 0) {
  98. $.ajax({
  99. url: "/profile/products?page=2",
  100. type: "GET",
  101. dataType: "script",
  102. success: loadNextPages
  103. });
  104. } else {
  105. continueExportNew();
  106. }
  107. }
  108.  
  109. function addExportButtonOld() {
  110. $(".pre-nav").append('<button style="float:right;" id="exportUnused">Export Unused Keys</button>');
  111. $("#exportUnused").click(exportUnusedOld);
  112. }
  113.  
  114. function exportUnusedOld() {
  115. var win = window.open("", "Groupees Keys Export", "width=480,height=640");
  116. $(".code:not([disabled])").each(function() {
  117. if (markUsed) $(this).parents(".product").find(".usage").click();
  118. win.document.write($(this).parents(".product").find("h3").text() + keySeparator + (keyOnNewLine ? "<br>" : "") + $(this).val() + (addWhiteLine ? "<br><br>" : "<br>"));
  119. });
  120. selectAll(win);
  121. }
  122.  
  123. function selectAll(win) {
  124. var range = win.document.createRange();
  125. range.selectNodeContents(win.document.body);
  126. var selection = win.window.getSelection();
  127. selection.removeAllRanges();
  128. selection.addRange(range);
  129. }
  130.  
  131. function SortByGame(a, b){
  132. var aName = a.game.toLowerCase();
  133. var bName = b.game.toLowerCase();
  134. return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
  135. }