ticketmaster-print

Print mobile tickets from ticketmaster

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         ticketmaster-print
// @version      2024-10-01
// @description  Print mobile tickets from ticketmaster
// @author       Kasper Laudrup
// @namespace    stacktrace.dk
// @grant        none
// @license      MIT
// @include      https://www.ticketmaster.tld/user/order/*/view*
// @require      https://code.jquery.com/jquery-latest.js
// ==/UserScript==

/* global $ */

(function() {
    'use strict';
    function print_ticket(title, contents) {
        var printWindow = window.open('', '', 'height=400,width=800');
        printWindow.document.write('<html><head><title>' + title + '</title>');
        printWindow.document.write('<style>span { display: block; }</style>');
        printWindow.document.write('</head><body><div style="width: 100%; text-align:center;">');
        printWindow.document.write('<h1>' + title + '</h1>');
        printWindow.document.write(contents);
        printWindow.document.write('</div></body></html>');
        printWindow.document.close();
        printWindow.print();
    }

    $(document).ready(function() {
        $("#main-content").on('DOMSubtreeModified', "#tickets-tabpanel", function() {
            var title = $('h1').first().text();
            var $qrcode = $(this).find('img').first();
            var $contents = $qrcode.parent().parent().parent().clone();
            var $button = $('#print-ticket');
            if (!$button.length) {
                var $input = $('<input id="print-ticket" type="button" value="Print" style="background-color: white; border: 1px solid; padding: 10px; text-align: center;"/>');
                $input.appendTo($("#tickets-tabpanel"));
                $(document).on('click','#print-ticket',function() {
                    print_ticket(title, $contents.html());
                });
            }
        });
    });
})();