restructured inject.js

This commit is contained in:
zino
2021-03-17 13:18:16 +01:00
parent 674f16bed7
commit 65cb9bff60
11 changed files with 179 additions and 240 deletions

View File

@@ -0,0 +1,44 @@
import * as I from "../types/types";
export function getVenueLocation(): string {
let span: string[] = [];
jQuery(".venue span").each(function () {
span.push(jQuery(this).text());
});
return span.join(", ");
}
export function getInputs(inContent: string, inInputsWithValue: I.InputsWithValue): void {
const parsedHTML: Node[] = $.parseHTML(inContent);
let inputs: I.Inputs = {};
jQuery(parsedHTML).find('input').each(function (this: any) {
const name: string = this.name;
const value: string = this.value;
if (value !== '')
inputs[name] = value;
});
inInputsWithValue = { ...inInputsWithValue, ...inputs };
}
// todo: check with different venues
export function getImportantNote(inInputsWithValue: I.InputsWithValue): void {
const importantNote: string | null = $(".important_note")[0].textContent;
if (importantNote?.trim().length) {
const importantNoteEncoded: string = encodeURIComponent(importantNote);
inInputsWithValue["importantNote"] = importantNote;
inInputsWithValue["importantNoteEncoded"] = importantNoteEncoded;
}
}
export function getAdditionalInputs(inContent: string, inInputsWithValue: I.InputsWithValue): void {
inInputsWithValue["event"] = inContent.match(/event:"(.+?)"/)![1];
inInputsWithValue["holdcode"] = inContent.match(/holdcode:"(.+?)"/)![1];
inInputsWithValue["posturlRaw"] = inContent.match(/posturl:"(.+?)"/)![1];
inInputsWithValue["posturlRawDecoded"] = decodeURIComponent(inInputsWithValue["posturlRaw"]);
inInputsWithValue["posturl"] = decodeURIComponent(`${inInputsWithValue["posturlRaw"]}&event=${inInputsWithValue["event"]}&holdcode=${inInputsWithValue["holdcode"]}&nocache=0&inclpkg=Y&incloffer=Y&inclcartdetails=Y&inclCart=Y&inclvenue=Y`);
inInputsWithValue["venueLocation"] = getVenueLocation();
}