diff --git a/client/package-lock.json b/client/package-lock.json index e0a478c..31b292b 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -9,10 +9,29 @@ "license": "ISC", "dependencies": { "browserify": "^17.0.0", + "jquery": "^3.6.0", "tsify": "^5.0.2", "uglify-js": "^3.13.0" + }, + "devDependencies": { + "@types/jquery": "^3.5.5" } }, + "node_modules/@types/jquery": { + "version": "3.5.5", + "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.5.tgz", + "integrity": "sha512-6RXU9Xzpc6vxNrS6FPPapN1SxSHgQ336WC6Jj/N8q30OiaBZ00l1GBgeP7usjVZPivSkGUfL1z/WW6TX989M+w==", + "dev": true, + "dependencies": { + "@types/sizzle": "*" + } + }, + "node_modules/@types/sizzle": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.2.tgz", + "integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==", + "dev": true + }, "node_modules/acorn": { "version": "7.4.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", @@ -985,6 +1004,11 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "node_modules/jquery": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz", + "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==" + }, "node_modules/jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", @@ -1764,6 +1788,21 @@ } }, "dependencies": { + "@types/jquery": { + "version": "3.5.5", + "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.5.tgz", + "integrity": "sha512-6RXU9Xzpc6vxNrS6FPPapN1SxSHgQ336WC6Jj/N8q30OiaBZ00l1GBgeP7usjVZPivSkGUfL1z/WW6TX989M+w==", + "dev": true, + "requires": { + "@types/sizzle": "*" + } + }, + "@types/sizzle": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.2.tgz", + "integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==", + "dev": true + }, "acorn": { "version": "7.4.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", @@ -2574,6 +2613,11 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "jquery": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz", + "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==" + }, "jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", diff --git a/client/package.json b/client/package.json index f40c6f6..1e626c2 100644 --- a/client/package.json +++ b/client/package.json @@ -11,7 +11,11 @@ "license": "ISC", "dependencies": { "browserify": "^17.0.0", + "jquery": "^3.6.0", "tsify": "^5.0.2", "uglify-js": "^3.13.0" + }, + "devDependencies": { + "@types/jquery": "^3.5.5" } } diff --git a/client/src/foobar.ts b/client/src/foobar.ts deleted file mode 100644 index e69de29..0000000 diff --git a/client/src/inject.ts b/client/src/inject.ts new file mode 100644 index 0000000..7f5032a --- /dev/null +++ b/client/src/inject.ts @@ -0,0 +1,78 @@ +import jQuery = require("jquery"); + +interface IinputsWithValue { + [HTMLInputElement: string]: string; +} + +interface IConfig { + debug: boolean, + branch: string +} + +const config: IConfig = { + debug: true, + branch: "staging" +} + +const checkoutParams: string[] = [ + 'APPTE', 'age_consent_is_checked', 'agency', 'cancelAndRedirectTrxState', 'cogid', 'coids', 'discount=A=IE', 'discount=A=IV', 'discountdesc=A=IE', 'discountdesc=A=IV', 'discountfees=A=IE', 'discountfees=A=IV', 'discountprice=A=IE', 'discountprice=A=IV', 'dpa_selection', 'etpgcode', 'flashDetected', 'gid', 'hbx_discount_prices', 'hbx_discounts', 'hbx_offered_pg', 'hbx_perf_codes', 'hbx_perf_sub_codes', 'hbx_pids', 'hbx_requested_pg', 'hbx_selected_tixx', 'hbx_upsell_flag', 'request_type', 'invalid_seats', 'inventory_filtering_action', 'inventory_month', 'inventory_year', 'isCapEnabled', 'is_availability_switch_from_map', 'is_ticket_exchange_request', 'ism_map_current_state_json_data', 'jcarousel_auto_off_val', 'listing_type', 'mainEventPID', 'map_coupon_code', 'mlbamsp', 'oid', 'ooids', 'orderkey', 'orgid', 'p_orgid', 'package_pids', 'parent_offer_id', 'pay_pal_token', 'pid', 'prevtrxstate', 'recapToken', 'redeem_voucher_data_event_mapping', 'replay_request', 'request_action', 's_mem_tkt_ren_retrieval', 'schedule', 'secure_trxn_enabled', 'selected_seat_indexes', 'selected_upsell_option', 'supplierCode', 'supplier_code', 'target_name_value', 'target_prev_trxstate', 'target_trxstate', 'target_url', 'timeout_seconds', 'trxstate', 'upsell_selected', 'user_context', 'valid_coupon_code_message' +]; + +jQuery(document).ready(() => { + const content: string = new XMLSerializer().serializeToString(document); + + const inputsWithValue: IinputsWithValue = getInputs(content); + console.log(inputsWithValue); + + checkTrxState(inputsWithValue, content); +}); + +function getInputs(inContent: string): IinputsWithValue { + let inputsWithValue: IinputsWithValue = {}; + const parsedHTML: Node[] = jQuery.parseHTML(inContent); + + jQuery(parsedHTML).find('input').each(function() { + if (this.value !== '' && checkoutParams.includes(this.name)) + inputsWithValue[this.name] = this.value; + }); + + inputsWithValue["posturl"] = inContent.match(/posturl:"(.+?)"/)![1]; + inputsWithValue["event"] = inContent.match(/event:"(.+?)"/)![1]; + inputsWithValue["holdcode"] = inContent.match(/holdcode:"(.+?)"/)![1]; + + return inputsWithValue; +} + +function checkTrxState(inInputsWithValue: IinputsWithValue, content: string): void { + if (!jQuery.isEmptyObject(inInputsWithValue)) { + if (inInputsWithValue.hasOwnProperty("trxstate") && inInputsWithValue["trxstate"] === "20") { + getImportantNote(inInputsWithValue); + showSeatmapButton(); + injectSeatmap(inInputsWithValue, content); + } + else if (inInputsWithValue.hasOwnProperty("prevtrxstate") && inInputsWithValue["prevtrxstate"] === "30") + console.log("prevtrxstate 30 identified"); + else + console.log("No action set: trxstate: " + inInputsWithValue["trxstate"]); + } +} + +// todo: check with different venues +function getImportantNote(inInputsWithValue: IinputsWithValue): void { + const importantNote: string | null = jQuery(".important_note")[0].textContent; + + if (importantNote !== null && importantNote.trim().length) { + const importantNoteEncoded: string = encodeURIComponent(importantNote); + inInputsWithValue["importantNote"] = importantNote; + inInputsWithValue["importantNoteEncoded"] = importantNoteEncoded; + } +} + +function showSeatmapButton(): void { + jQuery('#flash_seat_map_box_id').css('display', 'block'); + jQuery('#get_flash').css('display', 'none'); +} + +function injectSeatmap(inInputsWithValue: IinputsWithValue, content: string): void { + +} \ No newline at end of file diff --git a/client/tsconfig.json b/client/tsconfig.json index 1093bc3..08e8501 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -6,7 +6,11 @@ // "incremental": true, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ - // "lib": [], /* Specify library files to be included in the compilation. */ + "lib": [ + "es2016", + "dom", + "es5" + ], /* Specify library files to be included in the compilation. */ "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ @@ -73,5 +77,5 @@ ], "exclude": [ "node_modules" - ], -} + ] +} \ No newline at end of file