Bundle Stars Keys Retrieve

Retrieve keys from Bundle Stars

目前为 2017-04-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Bundle Stars Keys Retrieve
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Retrieve keys from Bundle Stars
  6. // @icon https://cdn.bundlestars.com/production/brand/apple-touch-icon-180x180.png
  7. // @author Bisumaruko
  8. // @include http*://*bundlestars.com/en/orders/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var anchor = document.querySelector('h2'),
  16. BSRetrive = document.createElement('div'),
  17. BSTextarea = document.createElement('textarea'),
  18. BSBtnContainer = document.createElement('div'),
  19. BSBtnReveal = document.createElement('button'),
  20. BSBtnRetrieve = document.createElement('button'),
  21. BSBtnCopy = document.createElement('button'),
  22. BSBtnReset = document.createElement('button'),
  23. BSCheckTitle = document.createElement('label'),
  24. BSCheckJoin = document.createElement('label'),
  25.  
  26. style = document.createElement('style');
  27.  
  28. BSRetrive.classList.add('BSRetrive');
  29. BSTextarea.classList.add('BSTextarea');
  30. BSBtnContainer.classList.add('BSBtnContainer');
  31. BSBtnReveal.classList.add('BSBtnReveal');
  32. BSBtnReveal.textContent = 'Reveal';
  33. BSBtnRetrieve.classList.add('BSBtnRetrieve');
  34. BSBtnRetrieve.textContent = 'Retrieve';
  35. BSBtnCopy.classList.add('BSBtnCopy');
  36. BSBtnCopy.textContent = 'Copy';
  37. BSBtnReset.classList.add('BSBtnReset');
  38. BSBtnReset.textContent = 'Reset';
  39.  
  40. BSCheckTitle.innerHTML = '<input type="checkbox" class="BSCheckTitle">Include Game Title';
  41. BSCheckJoin.innerHTML = '<input type="checkbox" class="BSCheckJoin">Join Keys';
  42.  
  43. style.type = 'text/css';
  44. style.innerHTML = `
  45. .BSRetrive {
  46. width: 100%;
  47. height: 200px;
  48. display: flex;
  49. flex-direction: column;
  50. box-sizing: border-box;
  51. border: 1px solid #424242;
  52. color: #999999;
  53. }
  54. .BSTextarea {
  55. width: 100%;
  56. height: 150px;
  57. border: none;
  58. background-color: #303030;
  59. color: #DDD;
  60. box-sizing: border-box;
  61. resize: none;
  62. }
  63. .BSBtnContainer {
  64. width: 100%;
  65. display: flex;
  66. padding-top: 5px;
  67. flex-grow: 1;
  68. box-sizing: border-box;
  69. }
  70. .BSBtnContainer > button {
  71. height: 34px;
  72. margin-right: 10px;
  73. padding: 6px 12px;
  74. border: 1px solid transparent;
  75. background-color: #262626;
  76. color: #dedede;
  77. box-sizing: border-box;
  78. outline: none;
  79. cursor: pointer;
  80. }
  81. .BSBtnContainer > button:hover {
  82. color: #A8A8A8;
  83. }
  84. .BSBtnContainer > label {
  85. margin-right: 10px;
  86. color: #dedede;
  87. }
  88. `;
  89.  
  90. BSBtnReveal.addEventListener('click', () => {
  91. var keys = document.querySelectorAll('a[ng-click^="redeemSerial"]');
  92.  
  93. for (let key of keys) {
  94. if (key.parentNode.classList.contains('ng-hide')) continue;
  95. if (!key.closest('td').classList.contains('key-container')) continue;
  96. key.click();
  97. }
  98. });
  99.  
  100. BSBtnRetrieve.addEventListener('click', () => {
  101. var keys = [],
  102. containers = document.querySelectorAll('td.key-container'),
  103. separator = document.querySelector('.BSCheckJoin').checked ? ',' : "\n";
  104.  
  105. for (let container of containers) {
  106. let title = container.previousElementSibling.textContent.trim(),
  107. key = container.querySelector('input').value.trim();
  108.  
  109. if (document.querySelector('.BSCheckTitle').checked) key = title + ', ' + key;
  110. keys.push(key);
  111. }
  112.  
  113. BSTextarea.textContent = keys.join(separator);
  114. });
  115.  
  116. BSBtnCopy.addEventListener('click', () => {
  117. BSTextarea.select();
  118. document.execCommand('copy');
  119. });
  120.  
  121. BSBtnReset.addEventListener('click', () => {
  122. BSTextarea.textContent = '';
  123. });
  124.  
  125. document.head.appendChild(style);
  126. BSBtnContainer.appendChild(BSBtnReveal);
  127. BSBtnContainer.appendChild(BSBtnRetrieve);
  128. BSBtnContainer.appendChild(BSBtnCopy);
  129. BSBtnContainer.appendChild(BSBtnReset);
  130. BSBtnContainer.appendChild(BSCheckTitle);
  131. BSBtnContainer.appendChild(BSCheckJoin);
  132. BSRetrive.appendChild(BSTextarea);
  133. BSRetrive.appendChild(BSBtnContainer);
  134. anchor.parentNode.insertBefore(BSRetrive, anchor);
  135. })();