Bundle Stars Keys Retrieve

Retrieve keys from Bundle Stars

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

// ==UserScript==
// @name         Bundle Stars Keys Retrieve
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Retrieve keys from Bundle Stars
// @icon         https://cdn.bundlestars.com/production/brand/apple-touch-icon-180x180.png
// @author       Bisumaruko
// @include      http*://*bundlestars.com/*orders/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var anchor = document.querySelector('h2'),
        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 = document.querySelectorAll('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 = document.querySelectorAll('td.key-container'),
            separator = document.querySelector('.BSCheckJoin').checked ? ',' : "\n";

        for (let container of containers) {
            let title = container.previousElementSibling.textContent.trim(),
                key = container.querySelector('input').value.trim();

            if (document.querySelector('.BSCheckTitle').checked) key = title + ', ' + 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);
})();