Bundle Stars Keys Retrieve

Retrieve keys from Bundle Stars

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

  1. // ==UserScript==
  2. // @name Bundle Stars Keys Retrieve
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.1
  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/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function getAnchor() {
  16. var anchor = document.querySelector('h2');
  17.  
  18. return anchor && anchor.textContent.trim() === 'Order Keys' ? anchor : null;
  19. }
  20.  
  21. function setup() {
  22. var anchor = getAnchor();
  23.  
  24. if (!anchor) return;
  25. var BSRetrive = document.createElement('div'),
  26. BSTextarea = document.createElement('textarea'),
  27. BSBtnContainer = document.createElement('div'),
  28. BSBtnReveal = document.createElement('button'),
  29. BSBtnRetrieve = document.createElement('button'),
  30. BSBtnCopy = document.createElement('button'),
  31. BSBtnReset = document.createElement('button'),
  32. BSCheckTitle = document.createElement('label'),
  33. BSCheckJoin = document.createElement('label'),
  34. style = document.createElement('style');
  35. BSRetrive.classList.add('BSRetrive');
  36. BSTextarea.classList.add('BSTextarea');
  37. BSBtnContainer.classList.add('BSBtnContainer');
  38. BSBtnReveal.classList.add('BSBtnReveal');
  39. BSBtnReveal.textContent = 'Reveal';
  40. BSBtnRetrieve.classList.add('BSBtnRetrieve');
  41. BSBtnRetrieve.textContent = 'Retrieve';
  42. BSBtnCopy.classList.add('BSBtnCopy');
  43. BSBtnCopy.textContent = 'Copy';
  44. BSBtnReset.classList.add('BSBtnReset');
  45. BSBtnReset.textContent = 'Reset';
  46. BSCheckTitle.innerHTML = '<input type="checkbox" class="BSCheckTitle">Include Game Title';
  47. BSCheckJoin.innerHTML = '<input type="checkbox" class="BSCheckJoin">Join Keys';
  48. style.type = 'text/css';
  49. style.innerHTML = `
  50. .BSRetrive {
  51. width: 100%;
  52. height: 200px;
  53. display: flex;
  54. flex-direction: column;
  55. box-sizing: border-box;
  56. border: 1px solid #424242;
  57. color: #999999;
  58. }
  59. .BSTextarea {
  60. width: 100%;
  61. height: 150px;
  62. border: none;
  63. background-color: #303030;
  64. color: #DDD;
  65. box-sizing: border-box;
  66. resize: none;
  67. }
  68. .BSBtnContainer {
  69. width: 100%;
  70. display: flex;
  71. padding-top: 5px;
  72. flex-grow: 1;
  73. box-sizing: border-box;
  74. }
  75. .BSBtnContainer > button {
  76. height: 34px;
  77. margin-right: 10px;
  78. padding: 6px 12px;
  79. border: 1px solid transparent;
  80. background-color: #262626;
  81. color: #dedede;
  82. box-sizing: border-box;
  83. outline: none;
  84. cursor: pointer;
  85. }
  86. .BSBtnContainer > button:hover {
  87. color: #A8A8A8;
  88. }
  89. .BSBtnContainer > label {
  90. margin-right: 10px;
  91. color: #dedede;
  92. }
  93. `;
  94. BSBtnReveal.addEventListener('click', () => {
  95. var keys = document.querySelectorAll('a[ng-click^="redeemSerial"]');
  96. for (let key of keys) {
  97. if (key.parentNode.classList.contains('ng-hide')) continue;
  98. if (!key.closest('td').classList.contains('key-container')) continue;
  99. key.click();
  100. }
  101. });
  102. BSBtnRetrieve.addEventListener('click', () => {
  103. var keys = [],
  104. containers = document.querySelectorAll('td.key-container'),
  105. separator = document.querySelector('.BSCheckJoin').checked ? ',' : "\n";
  106. for (let container of containers) {
  107. let title = container.previousElementSibling.textContent.trim(),
  108. key = container.querySelector('input').value.trim();
  109. if (document.querySelector('.BSCheckTitle').checked) key = title + ', ' + key;
  110. keys.push(key);
  111. }
  112. BSTextarea.textContent = keys.join(separator);
  113. });
  114. BSBtnCopy.addEventListener('click', () => {
  115. BSTextarea.select();
  116. document.execCommand('copy');
  117. });
  118. BSBtnReset.addEventListener('click', () => {
  119. BSTextarea.textContent = '';
  120. });
  121. document.head.appendChild(style);
  122. BSBtnContainer.appendChild(BSBtnReveal);
  123. BSBtnContainer.appendChild(BSBtnRetrieve);
  124. BSBtnContainer.appendChild(BSBtnCopy);
  125. BSBtnContainer.appendChild(BSBtnReset);
  126. BSBtnContainer.appendChild(BSCheckTitle);
  127. BSBtnContainer.appendChild(BSCheckJoin);
  128. BSRetrive.appendChild(BSTextarea);
  129. BSRetrive.appendChild(BSBtnContainer);
  130. anchor.parentNode.insertBefore(BSRetrive, anchor);
  131. }
  132.  
  133. function observeOrderDetails(target) {
  134. new MutationObserver(mutations => {
  135. for (let mutation of mutations) {
  136. if (!mutation.addedNodes.length) continue;
  137. if (mutation.addedNodes[0].classList.contains('ng-scope')) {
  138. setup();
  139. }
  140. }
  141. }).observe(target, {childList: true});
  142. }
  143.  
  144. var anchor = getAnchor();
  145.  
  146. if (anchor) {
  147. setup();
  148. observeOrderDetails(anchor.closest('body > div.ng-scope'));
  149. } else {
  150. var bodyObserver = new MutationObserver(mutations => {
  151. for (let mutation of mutations) {
  152. if (!mutation.addedNodes.length) continue;
  153. if (mutation.addedNodes[0].classList.contains('ng-scope')) {
  154. observeOrderDetails(mutation.addedNodes[0]);
  155. bodyObserver.disconnect();
  156. }
  157. }
  158. });
  159.  
  160. bodyObserver.observe(document.body, {childList: true});
  161. }
  162. })();