MTGTop8 to List/JSON

try to take over the world!

  1. // ==UserScript==
  2. // @name MTGTop8 to List/JSON
  3. // @namespace https://xvicario.us/scripts
  4. // @version 0.1.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match http://mtgtop8.com/compare
  8. // @grant none
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.4/js.cookie.min.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. const COOKIE_SNOW_LANDS = 'convertSnow';
  15. const controls =
  16. '<div class="W10" style="padding:7px">MTGTop8 to List/JSON</div>' +
  17. '<div class="W10">' +
  18. '<input type="checkbox" id="convertSnow">' +
  19. '<label for="convertSnow">Convert Snow Lands to Normal</label>' +
  20. '</div>' +
  21. '<div class="W10">' +
  22. '<a id="generateList" href="#">Generate List</a>' +
  23. '</div>';
  24. const $controls = $('<div class="c_box"></div>').html(controls);
  25. $controls.css('height', '66px').css('width', '250');
  26. const $table = $('div.page table').first();
  27. const $freeSpace = $table.find('tr td').first();
  28. $freeSpace.next().remove();
  29. $freeSpace.prop('align', 'center');
  30. $freeSpace.prop('colspan', '2');
  31. $freeSpace.append($controls);
  32. $(document).on('change', '#convertSnow', function() {
  33. Cookies.set(COOKIE_SNOW_LANDS, this.checked);
  34. });
  35. $('#convertSnow').prop('checked',
  36. Cookies.get(COOKIE_SNOW_LANDS) === 'true');
  37. $(document).on('click', '#generateList', function() {
  38. let nth = 0;
  39. let cards = [];
  40. const basicLands = ['Plains', 'Island', 'Swamp',
  41. 'Mountain', 'Forest', 'Wastes'];
  42. const snow = 'Snow-Covered';
  43. let log = '';
  44. $('tr').each(function() {
  45. if (nth > 8) {
  46. let $c2 = $(this).find('div.c2');
  47. if ($c2.text().length) {
  48. let number = 0;
  49. $(this).find('div.c').each(function() {
  50. const newNumber = parseInt($(this).text());
  51. if (newNumber > number) {
  52. number = newNumber;
  53. }
  54. });
  55. let basicName = $c2.text();
  56. if (basicName.includes(snow)) {
  57. basicName = basicName.substr(snow.length).trim();
  58. }
  59. if (number > 4 && !basicLands.includes(basicName)) {
  60. number = 4;
  61. }
  62. let editedName = basicName;
  63. if (Cookies.get(COOKIE_SNOW_LANDS) === 'false'
  64. && basicLands.includes(basicName)
  65. && $c2.text().includes(snow)) {
  66. editedName = snow + ' ' + basicName;
  67. }
  68. const currentIndex = searchForCard(editedName, cards);
  69. if (currentIndex > -1) {
  70. // todo: Snow-Covered lands are duplicated because they
  71. // aren't in the same row
  72. cards[currentIndex][0] += number;
  73. if (cards[currentIndex][0] > 4
  74. && !basicLands.includes(basicName)) {
  75. cards[currentIndex][0] = 4;
  76. }
  77. } else {
  78. cards.push([number, editedName]);
  79. }
  80. }
  81. }
  82. nth++;
  83. });
  84. for (let i = 0; i < cards.length; i++) {
  85. log += (cards[i][0] + 'x ' + cards[i][1]) + '<br>';
  86. }
  87. const myWindow = window.open('about:blank', '', '_blank');
  88. myWindow.document.write(log + '<br><br>' + JSON.stringify(cards));
  89. });
  90.  
  91. /**
  92. * Search for a card name in the multidimensional array
  93. * @param {string} name what card you're looking for
  94. * @param {array} array array you are looking in
  95. * @return {number} the index of the card, or -1 if it is not found
  96. */
  97. function searchForCard(name, array) {
  98. for (let i = 0; i < array.length; i++) {
  99. if (array[i][1] === name) {
  100. return i;
  101. }
  102. }
  103. return -1;
  104. }
  105. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址