Retrieve keys from Bundle Stars
当前为
// ==UserScript==
// @name Bundle Stars Keys Retrieve
// @namespace http://tampermonkey.net/
// @version 1.1.2
// @description Retrieve keys from Bundle Stars
// @icon https://cdn.bundlestars.com/production/brand/apple-touch-icon-180x180.png
// @author Bisumaruko
// @include http*://*bundlestars.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var $ = selector => document.querySelector(selector),
$$ = selector => Array.from(document.querySelectorAll(selector));
function getAnchor() {
var anchor = $('h2');
return anchor && anchor.textContent.trim() === 'Order Keys' ? anchor : null;
}
function setup() {
var anchor = getAnchor();
if (!anchor) return;
var BSRetrive = document.createElement('div'),
BSTextarea = document.createElement('textarea'),
BSBtnContainer = document.createElement('div'),
BSBtnReveal = document.createElement('button'),
BSBtnRetrieve = document.createElement('button'),
BSBtnCopy = document.createElement('button'),
BSBtnReset = document.createElement('button'),
BSCheckTitle = document.createElement('label'),
BSCheckJoin = document.createElement('label'),
style = document.createElement('style');
BSRetrive.classList.add('BSRetrive');
BSTextarea.classList.add('BSTextarea');
BSBtnContainer.classList.add('BSBtnContainer');
BSBtnReveal.classList.add('BSBtnReveal');
BSBtnReveal.textContent = 'Reveal';
BSBtnRetrieve.classList.add('BSBtnRetrieve');
BSBtnRetrieve.textContent = 'Retrieve';
BSBtnCopy.classList.add('BSBtnCopy');
BSBtnCopy.textContent = 'Copy';
BSBtnReset.classList.add('BSBtnReset');
BSBtnReset.textContent = 'Reset';
BSCheckTitle.innerHTML = '<input type="checkbox" class="BSCheckTitle">Include Game Title';
BSCheckJoin.innerHTML = '<input type="checkbox" class="BSCheckJoin">Join Keys';
style.type = 'text/css';
style.innerHTML = `
.BSRetrive {
width: 100%;
height: 200px;
display: flex;
flex-direction: column;
box-sizing: border-box;
border: 1px solid #424242;
color: #999999;
}
.BSTextarea {
width: 100%;
height: 150px;
border: none;
background-color: #303030;
color: #DDD;
box-sizing: border-box;
resize: none;
}
.BSBtnContainer {
width: 100%;
display: flex;
padding-top: 5px;
flex-grow: 1;
box-sizing: border-box;
}
.BSBtnContainer > button {
height: 34px;
margin-right: 10px;
padding: 6px 12px;
border: 1px solid transparent;
background-color: #262626;
color: #dedede;
box-sizing: border-box;
outline: none;
cursor: pointer;
}
.BSBtnContainer > button:hover {
color: #A8A8A8;
}
.BSBtnContainer > label {
margin-right: 10px;
color: #dedede;
}
`;
BSBtnReveal.addEventListener('click', () => {
var keys = $$('a[ng-click^="redeemSerial"]');
for (let key of keys) {
if (key.parentNode.classList.contains('ng-hide')) continue;
if (!key.closest('td').classList.contains('key-container')) continue;
key.click();
}
});
BSBtnRetrieve.addEventListener('click', () => {
var keys = [],
containers = $$('td.key-container'),
separator = $('.BSCheckJoin').checked ? ',' : "\n";
for (let container of containers) {
let key = container.querySelector('input'),
title = container.previousElementSibling;
if (!key) continue;
key = key.value.trim();
if (title && $('.BSCheckTitle').checked) key = title.textContent.trim() + ', ' + key;
keys.push(key);
}
BSTextarea.textContent = keys.join(separator);
});
BSBtnCopy.addEventListener('click', () => {
BSTextarea.select();
document.execCommand('copy');
});
BSBtnReset.addEventListener('click', () => {
BSTextarea.textContent = '';
});
document.head.appendChild(style);
BSBtnContainer.appendChild(BSBtnReveal);
BSBtnContainer.appendChild(BSBtnRetrieve);
BSBtnContainer.appendChild(BSBtnCopy);
BSBtnContainer.appendChild(BSBtnReset);
BSBtnContainer.appendChild(BSCheckTitle);
BSBtnContainer.appendChild(BSCheckJoin);
BSRetrive.appendChild(BSTextarea);
BSRetrive.appendChild(BSBtnContainer);
anchor.parentNode.insertBefore(BSRetrive, anchor);
}
function observeOrderDetails(target) {
new MutationObserver(mutations => {
for (let mutation of mutations) {
if (!mutation.addedNodes.length) continue;
if (mutation.addedNodes[0].classList.contains('ng-scope')) setup();
}
}).observe(target, {childList: true});
}
var anchor = getAnchor();
if (anchor) {
setup();
observeOrderDetails(anchor.closest('body > div.ng-scope'));
} else {
var bodyObserver = new MutationObserver(mutations => {
for (let mutation of mutations) {
if (!mutation.addedNodes.length) continue;
if (mutation.addedNodes[0].classList.contains('ng-scope')) {
observeOrderDetails(mutation.addedNodes[0]);
bodyObserver.disconnect();
}
}
});
bodyObserver.observe(document.body, {childList: true});
}
})();