From e750c22b92e2bbdb4c6dc718e13eadc866b7be4d Mon Sep 17 00:00:00 2001 From: luxick Date: Sat, 27 Jun 2026 19:18:21 +0200 Subject: [PATCH] Add Rotate Datasheet Card Backs for Printing --- js/rotate-datacard-backs.user.js | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 js/rotate-datacard-backs.user.js diff --git a/js/rotate-datacard-backs.user.js b/js/rotate-datacard-backs.user.js new file mode 100644 index 0000000..3cff6d7 --- /dev/null +++ b/js/rotate-datacard-backs.user.js @@ -0,0 +1,81 @@ +// ==UserScript== +// @name Rotate Datasheet Card Backs for Printing +// @namespace local.print.helper +// @version 3.0 +// @description Adds a button to the print sidebar that rotates the outer wrapper of every unit-card-back card 180 degrees +// @match *://game-datacards.eu/* +// @grant none +// @run-at document-idle +// ==/UserScript== + +(function () { + 'use strict'; + + function rotateCardBacks() { + var wrappers = document.querySelectorAll('.unit-card-back-wrapper'); + var count = 0; + + wrappers.forEach(function (wrapper) { + var outer = wrapper.parentElement; + if (!outer) return; + + var current = outer.style.rotate; + if (current === '180deg') { + outer.style.rotate = '0deg'; + } else { + outer.style.rotate = '180deg'; + } + count++; + }); + + console.log('Rotated ' + count + ' card back(s).'); + return count; + } + + function createButton() { + var button = document.createElement('button'); + button.id = 'rotate-card-backs-button'; + button.textContent = 'Rotate card backs'; + button.style.display = 'block'; + button.style.width = '100%'; + button.style.marginTop = '10px'; + button.style.padding = '8px 12px'; + button.style.background = '#381a3a'; + button.style.color = 'white'; + button.style.border = 'none'; + button.style.borderRadius = '4px'; + button.style.cursor = 'pointer'; + button.style.fontFamily = 'sans-serif'; + button.style.fontSize = '13px'; + + button.addEventListener('click', rotateCardBacks); + return button; + } + + function tryAddButton() { + var sidebar = document.querySelector('.print-settings-scroll'); + if (!sidebar) return false; + + // Avoid adding the button more than once. + if (document.getElementById('rotate-card-backs-button')) return true; + + sidebar.appendChild(createButton()); + console.log('Rotate card backs button added to the sidebar.'); + return true; + } + + // Try right away in case the sidebar is already there. + if (tryAddButton()) return; + + // Otherwise watch the page until the sidebar appears. + var observer = new MutationObserver(function () { + if (tryAddButton()) { + observer.disconnect(); + } + }); + + observer.observe(document.documentElement, { + childList: true, + subtree: true + }); +})();