From 65cb9bff604626221ca664b34b9e7ce308cda79a Mon Sep 17 00:00:00 2001 From: zino Date: Wed, 17 Mar 2021 13:18:16 +0100 Subject: [PATCH] restructured inject.js --- client/src/inject.ts | 175 +++------------------- client/src/{ => modules}/communication.ts | 2 +- client/src/modules/config.ts | 16 ++ client/src/modules/parser.ts | 44 ++++++ client/src/modules/ui.ts | 71 +++++++++ client/src/{ => modules}/utils.ts | 0 client/src/{ => modules}/xml.ts | 5 +- client/src/seatmap.ts | 38 ++--- client/src/{types.ts => types/types.d.ts} | 45 +----- client/src/ui.ts | 21 --- client/tsconfig.json | 2 +- 11 files changed, 179 insertions(+), 240 deletions(-) rename client/src/{ => modules}/communication.ts (98%) create mode 100644 client/src/modules/config.ts create mode 100644 client/src/modules/parser.ts create mode 100644 client/src/modules/ui.ts rename client/src/{ => modules}/utils.ts (100%) rename client/src/{ => modules}/xml.ts (98%) rename client/src/{types.ts => types/types.d.ts} (84%) delete mode 100644 client/src/ui.ts diff --git a/client/src/inject.ts b/client/src/inject.ts index f444494..e5660ac 100644 --- a/client/src/inject.ts +++ b/client/src/inject.ts @@ -1,30 +1,18 @@ -// import $, { Callbacks } from 'jquery'; -var $ = require("jquery"); +var jQuery = require("jquery"); import 'jquery-ui'; -import * as I from "./types"; -import Utils from './utils'; -import * as communication from "./communication"; +import * as I from "./types/types"; +import Utils from './modules/utils'; +import * as Communication from "./modules/communication"; +import * as Parser from './modules/parser'; +import * as UI from "./modules/ui"; +import { config } from "./modules/config"; -export const config: I.Config = { - debug: true, - branch: "staging", - urlSeatmapStaging: "https://staging.tickets.zinomedia.de", - urlSeatmapMaster: "https://tickets.zinomedia.de", - urlCSSChildMaster: "https://tickets.zinomedia.de/dist/styleChild.css", - urlCSSChildStaging: "https://staging.tickets.zinomedia.de/dist/styleChild.css", - urlCSSParentMaster: "https://tickets.zinomedia.de/dist/styleParent.css", - urlCSSParentStaging: "https://staging.tickets.zinomedia.de/dist/styleParent.css", - urlJSCStaging: "https://staging.tickets.zinomedia.de/libs/jQuery-Seat-Charts/jquery.seat-charts.min.js", - urlJSCMaster: "https://tickets.zinomedia.de/libs/jQuery-Seat-Charts/jquery.seat-charts.min.js", - urlCSSJSCStaging: "https://staging.tickets.zinomedia.de/libs/jQuery-Seat-Charts/jquery.seat-charts.css", - urlCSSJSCMaster: "https://tickets.zinomedia.de/libs/jQuery-Seat-Charts/jquery.seat-charts.css" -} let inputsWithValue: I.InputsWithValue; let childHasVenueXML: boolean = false; window.addEventListener('load', function () { const content: string = new XMLSerializer().serializeToString(document); - getInputs(content); + Parser.getInputs(content, inputsWithValue) console.log(inputsWithValue["trxstate"]); console.log(/posturl:"(.+?)"/.test(content)); @@ -34,16 +22,17 @@ window.addEventListener('load', function () { return; Utils.inject(config.urlCSSParentStaging, "css", "body"); - communication.listenToMessages(messagesHandler); - getAdditionalInputs(content); - console.log(inputsWithValue); - getImportantNote(); + Communication.listenToMessages(messagesHandler); + Parser.getAdditionalInputs(content, inputsWithValue); + Parser.getImportantNote(inputsWithValue); jQuery(".flash_seat_map_box").remove(); - injectBookingBtn(); - createDialog(); + UI.injectBookingBtn(); + UI.createDialog(childHasVenueXML); + + console.log(inputsWithValue); jQuery("#foobarParent").on("click", () => { - communication.sendEventToChild("parent_init_venue"); + Communication.sendEventToChild("parent_init_venue"); }); }); @@ -55,7 +44,6 @@ function messagesHandler(e: any) { console.log(`parent: received from ${data.from}`); console.log(data); - switch (data.event) { case "child_init_needInputsWithValue": { const message: I.Message = { @@ -64,17 +52,17 @@ function messagesHandler(e: any) { event: "parent_init_sendInputsWithValue", date: Date.now() }; - communication.sendMessage(message, "iframeSeatmap") + Communication.sendMessage(message, "iframeSeatmap") break; } case "child_init_needVenueXML": { - communication.sendXML(inputsWithValue["posturl"], "iframeSeatmap", "parent_init_sendVenueXML", "parent"); + Communication.sendXML(inputsWithValue["posturl"], "iframeSeatmap", "parent_init_sendVenueXML", "parent"); childHasVenueXML = true; break; } case "child_needSeatmapXML": { - const seatmapUrl: string = generateSeatmapUrl(data.message); - communication.sendXML(seatmapUrl, "iframeSeatmap", "parent_sendSeatmapXML", "parent"); + const seatmapUrl: string = `${inputsWithValue["posturlRawDecoded"]}&inclseatmap=Y&seatmap=${data.message}` + Communication.sendXML(seatmapUrl, "iframeSeatmap", "parent_sendSeatmapXML", "parent"); break; } case "child_seatmap_ready": { @@ -85,127 +73,4 @@ function messagesHandler(e: any) { default: break; } -} - -function generateSeatmapUrl(seatmapId: string): string { - return `${inputsWithValue["posturlRawDecoded"]}&inclseatmap=Y&seatmap=${seatmapId}`; -} - -function getVenueLocation(): string { - let span: string[] = []; - jQuery(".venue span").each(function () { - span.push(jQuery(this).text()); - }); - - return span.join(", "); -} - -function getInputs(inContent: string): void { - const parsedHTML: Node[] = $.parseHTML(inContent); - let inputs: { [key: string]: string } = {}; - - $(parsedHTML).find('input').each(function (this: any) { - const name: string = this.name; - const value: string = this.value; - if (value !== '') - inputs[name] = value; - }); - - inputsWithValue = { ...inputsWithValue, ...inputs }; -} - - -// todo: check with different venues -function getImportantNote(): void { - const importantNote: string | null = $(".important_note")[0].textContent; - - if (importantNote?.trim().length) { - const importantNoteEncoded: string = encodeURIComponent(importantNote); - inputsWithValue["importantNote"] = importantNote; - inputsWithValue["importantNoteEncoded"] = importantNoteEncoded; - } -} - -function createDialog(): void { - jQuery("#dialogSeatmap").append($("