Idle-Pixel TCG Exporter

Export a table of all your cards

  1. // ==UserScript==
  2. // @name Idle-Pixel TCG Exporter
  3. // @namespace luxferre.dev
  4. // @version 1.0.0
  5. // @description Export a table of all your cards
  6. // @author Lux-Ferre
  7. // @license MIT
  8. // @match *://idle-pixel.com/login/play*
  9. // @grant none
  10. // @require https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
  11. // @require https://greasyfork.org/scripts/491983-idlepixel-plugin-paneller/code/IdlePixel%2B%20Plugin%20Paneller.js?anticache=20241218
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. class TCGExport extends IdlePixelPlusPlugin {
  18. constructor() {
  19. super("tcg_export", {
  20. about: {
  21. name: GM_info.script.name,
  22. version: GM_info.script.version,
  23. author: GM_info.script.author,
  24. description: GM_info.script.description
  25. }
  26. })
  27. this.card_data = {}
  28. }
  29.  
  30. onLogin() {
  31. this.createModal()
  32. Paneller.registerPanel("tcg_export", "Export TCG to Clipboard", IdlePixelPlus.plugins.tcg_export.export_click)
  33. }
  34. onMessageReceived(data) {
  35. if (!data.startsWith("REFRESH_TCG=")){return}
  36. this.card_data = {}
  37. const input = data.slice(12)
  38. const values = input.split("~");
  39. for (let i = 0; i < values.length; i += 3) {
  40. if (i + 2 < values.length) {
  41. const name = values[i + 1];
  42. const holo = values[i + 2].toLowerCase() === "true"
  43. if (!(name in this.card_data)) {
  44. this.card_data[name] = {
  45. base: 0,
  46. holo: 0
  47. }
  48. }
  49. if(holo){
  50. this.card_data[name].holo += 1
  51. } else {
  52. this.card_data[name].base += 1
  53. }
  54. }
  55. }
  56. }
  57. createModal(){
  58. const modalString = `
  59. <div id="tcg_export_modal" class="modal fade" data-bs-theme="dark" role="dialog" tabindex="-1"">
  60. <div class="modal-dialog" role="document">
  61. <div class="modal-content">
  62. <div class="modal-body" style="overflow: hidden">
  63. <div id="tcg_export_response" class="text-center" style="color: white;"></div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. `
  69.  
  70. const modalElement = $.parseHTML(modalString)
  71. $(document.body).append(modalElement)
  72. }
  73. export_click(){
  74. IdlePixelPlus.sendMessage("RFRESH_TCG_CLIENT")
  75. setTimeout(() => {
  76. IdlePixelPlus.plugins.tcg_export.export()
  77. }, 3000)
  78. }
  79. export(){
  80. let csv = `id,base,holo\n`
  81. for (const [key, value] of Object.entries(this.card_data)) {
  82. const new_row = `${key},${value.base},${value.holo}\n`
  83. csv += new_row
  84. }
  85. this.copy_to_clipboard(csv)
  86. }
  87.  
  88. copy_to_clipboard(text) {
  89. navigator.clipboard.writeText(text).then(() => {
  90. $("#tcg_export_response").text("Text copied to clipboard!")
  91. $("#tcg_export_modal").modal("show")
  92. }).catch(err => {
  93. $("#tcg_export_response").text(`Error copying text: ${err}`)
  94. $("#tcg_export_modal").modal("show")
  95. });
  96. }
  97. }
  98.  
  99. const plugin = new TCGExport();
  100. IdlePixelPlus.registerPlugin(plugin);
  101. })();