Last active
October 13, 2026 02:38
-
-
Save feildmaster/c7ddffd9e7dc5120fe234ac744393c04 to your computer and use it in GitHub Desktop.
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 Chat Deck Viewer | |
| // @namespace https://uc.feildmaster.com/ | |
| // @version 1.0.2 | |
| // @description Translate deck codes into buttons | |
| // @author feildmaster | |
| // @match https://*.undercards.net/* | |
| // @exclude https://*undercards.net/*/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=undercards.net | |
| // @require https://raw.githubusercontent.com/UCProjects/UnderScript/master/src/checkerV2.js | |
| // @downloadURL https://gist.github.com/feildmaster/c7ddffd9e7dc5120fe234ac744393c04/raw/chatDeck.user.js | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| const REGEX = /(?:[A-Za-z0-9+/]{4}){10,}(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?/g; | |
| const SOULS = ['KINDNESS', 'DETERMINATION', 'PATIENCE', 'BRAVERY', 'JUSTICE', 'PERSEVERANCE', 'INTEGRITY']; | |
| const underscript = window.underscript; | |
| const plugin = underscript.plugin(GM_info.script.name, GM_info.script.version); | |
| const eventManager = plugin.events; | |
| plugin.updater(GM_info.script.downloadURL); | |
| const type = plugin.settings().add({ key: 'Allow Decks', options: ['Complete', 'Partial'] }); | |
| const allCards = new Map(); | |
| const allArtifacts = new Map(); | |
| const pending = []; | |
| let style; | |
| let artifactsLoaded = false; | |
| let artifactsRequest; | |
| function loadArtifacts() { | |
| artifactsRequest ??= underscript.user.getAllArtifacts().then((arts) => { | |
| arts.forEach((art) => { | |
| if (art.unavailable || art.disabled) return; | |
| allArtifacts.set(art.id, art); | |
| }); | |
| artifactsLoaded = true; | |
| }); | |
| return artifactsRequest; | |
| } | |
| eventManager.on('allCardsReady', (cards) => { | |
| cards.forEach((card) => { | |
| if (card.rarity === 'TOKEN') return; | |
| allCards.set(card.id, card); | |
| }); | |
| pending.splice(0).forEach((args) => process(...args)); | |
| }); | |
| eventManager.on('Chat:getHistory', (data) => { | |
| JSON.parse(data.history).forEach((message) => process(message, data.room, true)); | |
| }); | |
| eventManager.on('Chat:getMessage Chat:getPrivateMessage', (data) => process(JSON.parse(data.chatMessage), data.room)); | |
| function process(message, room) { | |
| if (!allCards.size) { | |
| pending.push([message, room]); | |
| return; | |
| } | |
| const element = document.querySelector(`#${room} #message-${message.id} .chat-message`); | |
| if (!element?.textContent) return; // Message not on screen | |
| if (!hasDeck(element.textContent)) return; | |
| if (!artifactsLoaded) { | |
| loadArtifacts().then(() => process(message, room)); | |
| return; | |
| } | |
| if (!style) { | |
| style = plugin.addStyle( | |
| '.view-deck-button { display: table; }', | |
| '.container { display: flex; flex-wrap: wrap; }', | |
| '#cards .list-group-item { font-size: 13px; background-color: #000; color: #fff; border-color: #fff; height: 21px; padding: 0 0 0 5px; }', | |
| ); | |
| } | |
| // if (!enabled.value()) return; | |
| const { text, decks } = build(element.textContent); | |
| if (!decks.length) return; | |
| // Add buttons | |
| element.textContent = text; // || 'sent a deck code'; // Default message? | |
| $(element).after(...decks.map((deck) => button(deck))) | |
| } | |
| function build(message) { | |
| const decks = []; | |
| const text = message.replaceAll(REGEX, (code) => { | |
| const deck = validate(code); | |
| if (!deck) return code; | |
| decks.push(deck); | |
| return ''; | |
| }).trim(); | |
| return { text, decks } | |
| } | |
| function hasDeck(message) { | |
| return Boolean(message.match(REGEX)?.some((code) => parse(code))); | |
| } | |
| function parse(code) { | |
| if (!allCards.size) return null; | |
| try { | |
| const { soul, cardIds, artifactIds } = JSON.parse(atob(code)); | |
| if (!SOULS.includes(soul)) return null; | |
| const complete = type.value() === 'Complete'; | |
| const cards = cardIds.map((id) => allCards.get(Number(id))).filter(_ => _); | |
| if (complete ? cards.length !== 25 : !cards.length) return null; | |
| return { soul, cards, artifactIds, complete }; | |
| } catch { | |
| return null; | |
| } | |
| } | |
| function validate(code) { | |
| const parsed = parse(code); | |
| if (!parsed) return false; | |
| const { soul, cards, artifactIds, complete } = parsed; | |
| try { | |
| const artifacts = artifactIds.map((id) => allArtifacts.get(Number(id))).filter(_ => _); | |
| if (!artifacts.length) return false; | |
| const legend = artifacts.some((art) => art.legendary); | |
| if (complete && (legend ? artifacts.length !== 1 : artifacts.length !== 2)) return false; | |
| return { artifacts, cards, code, soul } | |
| } catch { | |
| return false; | |
| } | |
| } | |
| function button(deck) { | |
| return $('<div>') | |
| .text('View Deck') | |
| .addClass('btn btn-sm btn-primary view-deck-button') | |
| .click(() => view(deck)); | |
| } | |
| function view({ artifacts, cards, code, soul }) { | |
| BootstrapDialog.show({ | |
| title: 'View Deck', | |
| message: ` | |
| <div> | |
| <button class="btn btn-sm btn-success"><span class="glyphicon glyphicon-link"></span></button> Deck Code | |
| <input class="form-control" value="${code}" readonly /> | |
| </div> | |
| <hr> | |
| <div> | |
| <img src="images/souls/${soul}.png" /> <span class="${soul}">${soul}</span> | |
| </div> | |
| <div id="artifacts"></div> | |
| <div id="cards"></div> | |
| `.replace(/\n/g, ''), | |
| size: window.appendCard ? BootstrapDialog.SIZE_WIDE : undefined, | |
| onshown(dialog) { | |
| const body = dialog.$modalBody; | |
| body.find('button').click(() => { | |
| body.find('input').select(); | |
| navigator.clipboard.writeText(code); | |
| }); | |
| addArtifacts(artifacts, body.find('#artifacts')); | |
| addCards(cards, body.find('#cards')); | |
| }, | |
| buttons: [{ | |
| label: 'Close', | |
| cssClass: 'btn-danger', | |
| action(dialog) { | |
| dialog.close(); | |
| } | |
| }], | |
| }); | |
| } | |
| function addArtifacts(artifacts, arts) { | |
| artifacts.forEach((artifact) => { | |
| const artifactClass = artifact.legendary ? 'legendaryArtifact' : 'normalArtifact'; | |
| arts.append(`<span><img style="height: 32px;" src="images/artifacts/${artifact.image}.png" class="${artifactClass}" /> ${$.i18n(`artifact-name-${artifact.id}`)}</span> `); | |
| }); | |
| } | |
| function addCards(cards, element) { | |
| const append = window.appendCard; | |
| const canAppend = typeof append === 'function'; | |
| const wrapper = canAppend ? $('<div>').addClass('container cardsPreview') : $('<ul>').addClass('list-group'); | |
| if (canAppend) { | |
| cards.forEach((card) => append(card, wrapper)); | |
| } else { | |
| cards.forEach((card) => { | |
| wrapper.append(`<li class="list-group-item${card.shiny ? ' shiny' : ''}">${card.shiny ? '<span class="rainbowText">S</span> ': ''}<span class="${card.rarity}">${$.i18n(`card-name-${card.id}`, 1)}</span> (${card.cost})</li>`) | |
| }); | |
| } | |
| element.append(wrapper); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment