Last active
February 13, 2021 17:51
-
-
Save yurighensev/106a8c50663c58fe7a1df008a1aeb189 to your computer and use it in GitHub Desktop.
Deckbox deck page improvements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Deckbox deck page improvements | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.1 | |
| // @description Adds a list of missing cards to the bottom of the screen. Shows full deck names on the list. | |
| // @author You | |
| // @match https://deckbox.org/sets/* | |
| // @exclude https://deckbox.org/sets/ | |
| // @exclude https://deckbox.org/sets/1866383 | |
| // @grant GM_log | |
| // @updateURL https://gist.github.com/yurighensev/106a8c50663c58fe7a1df008a1aeb189/ | |
| // @require https://code.jquery.com/jquery-2.1.4.min.js | |
| // ==/UserScript== | |
| function createMissingCardsBox() { | |
| function createHolder() { | |
| var holder = document.createElement('div'); | |
| holder.id = 'missing-cards-holder'; | |
| holder.setStyle('border: 2px solid #517ca1; background-color: #fff; width: 290px; height: 300px; position: fixed; left:3px; bottom: 3px; padding: 3px 5px; overflow: auto'); | |
| document.body.append(holder); | |
| var buttons = document.createElement('div'); | |
| buttons.setStyle('position:absolute; top:0; right:0') | |
| buttons.append(createSideboardButton()); | |
| buttons.append(createCopyButton()); | |
| holder.append(buttons); | |
| return holder; | |
| }; | |
| function holder() { | |
| return document.getElementById('missing-cards-holder') || createHolder(); | |
| } | |
| function createCopyButton() { | |
| var copyButton = document.createElement('button'); | |
| copyButton.setStyle('position:relative'); | |
| copyButton.textContent = 'copy'; | |
| $(copyButton).on('click', function() { | |
| var copiedContent = ''; | |
| $(holder).find('div.holder-card').each(function(_, el) { | |
| copiedContent += el.textContent + "\n"; | |
| }); | |
| copyToClipboard(copiedContent); | |
| }); | |
| return copyButton; | |
| }; | |
| function createSideboardButton() { | |
| var sideButton = document.createElement('button'); | |
| sideButton.setStyle('position:relative'); | |
| sideButton.textContent = 'main'; | |
| $(sideButton).on('click', function() { | |
| if (this.textContent == 'side') { | |
| this.textContent = 'main' | |
| clearHolderCards(); | |
| populateHolder(deckTable('main'), holder()); | |
| } else { | |
| this.textContent = 'side' | |
| clearHolderCards(); | |
| populateHolder(deckTable('sideboard'), holder()); | |
| } | |
| }); | |
| return sideButton; | |
| } | |
| function clearHolderCards() { | |
| $(holder()).find('div.holder-card').remove(); | |
| } | |
| function copyToClipboard(selectedContent) { | |
| var $tempClipboardArea = $('<textarea>'); | |
| $('body').append($tempClipboardArea); | |
| $tempClipboardArea.val(selectedContent).select(); | |
| document.execCommand('copy'); | |
| $tempClipboardArea.remove(); | |
| }; | |
| function deckTable(section) { | |
| var index = (section == 'main') ? 0 : 1; | |
| return document.getElementsByClassName('bordered_table')[index]; | |
| }; | |
| function cardName(tr) { | |
| return tr.getElementsBySelector('td.card_name')[0].textContent.trim(); | |
| }; | |
| function missingQuantity(tr) { | |
| var inventory_count = parseInt(tr.getElementsBySelector('td.inventory_count')[0].textContent); | |
| var deck_count = parseInt(tr.getElementsBySelector('td.deck_count')[0].textContent); | |
| return deck_count - inventory_count; | |
| }; | |
| function populateHolder(table, holder) { | |
| table.getElementsBySelector('td.error').each(function(el) { | |
| var tr = el.parentNode; | |
| var card_name = cardName(tr); | |
| var missing = missingQuantity(tr); | |
| var line = document.createElement('div'); | |
| line.addClassName('holder-card') | |
| line.innerText = missing + ' ' + card_name; | |
| holder.append(line); | |
| }); | |
| } | |
| populateHolder(deckTable('main'), holder()); | |
| }; | |
| function showFullDeckNames() { | |
| $('li.submenu_entry.deck a').each(function(el) { | |
| var fullDeckName = $(this).attr('data-title'); | |
| $(this).contents().last().replaceWith(fullDeckName); | |
| }); | |
| }; | |
| (function() { | |
| document.getElementsByClassName('leaderboard')[0].remove(); | |
| createMissingCardsBox(); | |
| showFullDeckNames(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment