Bundle Stars Keys Retrieve

Retrieve keys from Bundle Stars

目前為 2017-04-24 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Bundle Stars Keys Retrieve
// @namespace    http://tampermonkey.net/
// @version      1.1.0
// @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';

    function setup() {
        var anchor = document.querySelector('h2');

        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 = 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);
    }

    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 = document.querySelector('h2');

    if (anchor) {
        setup();
        observeOrderDetails(anchor.closest('body > div.ng-scope'));
    } else {
        console.log('body');
        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});
    }
})();

QingJ © 2025

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