Greasy Fork 还支持 简体中文。

Groupees - Keys Exporter

Export steam keys and mark them as used

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

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